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 whether XOR of all numbers in a given range is even or odd
- Check whether Bishop can take down Pawn or not
- Check if it is possible to move from (a, 0) to (b, 0) with given jumps
- Check whether bitwise OR of N numbers is Even or Odd
- Check if it is possible to move from (0, 0) to (x, y) in N steps
- Check if a string has m consecutive 1's or 0's
- Check if a number is Palindrome
- Check if the given string is K-periodic
- Check if a number has digits in the given Order
- Check if a cell can be visited more than once in a String
- Check if it is possible to sort the array after rotating it
- Check if concatenation of two strings is balanced or not
- Check if a point is inside, outside or on the parabola
- Check if a point is inside, outside or on the ellipse
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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