Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Generate Binary Numbers from 1 to N
On this page

Problem Statement

Examples

Try it yourself

Problem Statement

Given an integer N, generate all binary numbers from 1 to N and return them as a list of strings.

Examples

Example 1

  • Input: N = 2
  • Output: ["1", "10"]
  • Explanation: The binary representation of 1 is "1", and the binary representation of 2 is "10".

Example 2

  • Input: N = 3
  • Output: ["1", "10", "11"]
  • Explanation: The binary representation of 1 is "1", the binary representation of 2 is "10", and the binary representation of 3 is "11".

Example 3

  • Input: N = 5
  • Output: ["1", "10", "11", "100", "101"]
  • Explanation: These are the binary representations of the numbers from 1 to 5.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Examples

Try it yourself