![]() |
VOOZH | about |
Given two positive integer numbers L and R. The task is to convert all the numbers from L to R to binary number. The length of all binary numbers should be same.
Examples:
Input: L = 2, R = 4
Output:
010
011
100
Explanation: The binary representation of the numbers: 2 = 10, 3 = 11 and 4 = 100.
For the numbers to have same length one preceding 0 is added to the binary representation of both 3 and 4.Input: L = 2, R = 8
Output:
0010
0011
0100
0101
0110
0111
1000
Approach: Follow the approach mentioned below to solve the problem.
Below is the implementation of the above approach
0010 0011 0100 0101 0110 0111 1000
Time Complexity: O(N * logR) where N = (R - L + 1)
Auxiliary Space: O(N * logR)