Programmers / Next Bigger Number
Problem
- Link
- Description
- Find and return the next number that has the same number of 1s when converted to binary
- Type
- Brute Force
Solution 1
| |
- Description
- Convert n to binary and count the number of 1s
- Increment one by one, count the number of 1s, and check if it matches n’s count
- Time Complexity
- O(1)
- The size of n does not affect time complexity
- Space Complexity
- O(1)
- Function parameters and local variables