Given some weights of masses a0, a1, a2, …, a100, a being an integer, and a weighing scale where weights can be put on both the sides of the scale. Check whether a particular item of weight W can be measured using these weights and scale.
Constraints: 2 ≤ W ≤ 109
Input : a = 2, W = 5
Output : YES
Explanation : Weights of masses (20 = 1) and (22 = 4) can be placed on one side of the scale and the item can be placed on other side, i.e. 1 + 4 = 5
Input : a = 4, W = 11
Output : YES
Explanation : Weights of masses (40 = 1) and (41 = 4) and the item can be placed on one side and a weight of mass (42 = 16) can be placed on the other side, i.e. 1 + 4 + 11 = 16
Input : a = 4, W = 7
Output : NO
item or including current weight to the opposite side containing item or by not using that weight at all.
Below is the implementation of above approach .
YES YES NO
Time Complexity: O(3N), where N cannot be more than 20 since 420 is greater than 109
- How to make the cursor to hand when a user hovers over a list item using CSS?
- Check if two given Circles are Orthogonal or not
- Check if it is possible to move from (a, 0) to (b, 0) with given jumps
- Check if it is possible to move from (0, 0) to (x, y) in N steps
- Check whether bitwise OR of N numbers is Even or Odd
- Check if a string has m consecutive 1's or 0's
- Check if the given string is K-periodic
- Check if a number is Palindrome
- Check whether XOR of all numbers in a given range is even or odd
- Check whether Bishop can take down Pawn or not
- Check if a point is inside, outside or on the ellipse
- Check if the given 2-D points form T-shape or not
- Check if a point is inside, outside or on the parabola
- Check if concatenation of two strings is balanced or not
- Check for balanced parenthesis without using stack
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Rajput-Ji