Question: this problem should be solved with c # A non-negative integer is called sparse if its binary representation does not contain two consecutive bits set
this problem should be solved with c #
A non-negative integer is called sparse if its binary representation does not contain two consecutive bits set to 1. For example, 40 is sparse because its binary representation is "101000", which does not contain two consecutive 1s. On the other hand, 26 is not sparse because its binary representation is "11010", which does contain two consecutive 1s. The next sparse for given integer N is the smallest sparse greater than N. For example, given integer: N= 38, the next sparse is 40; N = 21, the next sparse is 32. Write a function: class solution { public int solution(int N); } that, given an integer N, returns the next sparse. For example, given: N = 38, the function should return 40, N = 21, the function should return 32, as explained above. Write an efficient algorithm for the following assumptions: Nis an integer within the range [0...1,073,741,824)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
