To solve this problem, you'll have to open it on the computer

Generate binary numbers from 1 to n

Queues
medium
Score: 20

Given a number n, generate all binary numbers with decimal values from 1 to N and return the array of binary number.

Input Format

First Parameter - number n.

Output Format

Return the array of strings.

Example 1:

Input: 3
Output:  1 10 11
Explanation:  Binary numbers from 1 to 3 are 1 , 10 and 11 .

Example 2:

Input: 6
Output: 1 10 11 100 101 110
Explanation:  Binary numbers from 1 to 6 are 1, 10, 11, 100, 101 and 110 .  

Constraints

  • 1 ≤ N ≤ 105
  • Expected Time Complexity : O(N)
  • Expected Space Complexity: O(N)
Submit code to see the your result here