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 a number is divisible by 41 or not
- Check if a string has m consecutive 1's or 0's
- Check if a number is Palindrome
- 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 it is possible to move from (a, 0) to (b, 0) with given jumps
- Check if two numbers are bit rotations of each other or not
- Check if moves in a stack or queue are possible or not
- Check if the given decimal number has 0 and 1 digits only
- Check if a value is present in an Array in Java
- Check if a word exists in a grid or not
- Program to check the number is Palindrome or not
- Check if the given graph represents a Bus Topology
- Check all the elements in an array are even using library in C++
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