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

0% completed

Generate Binary Numbers from 1 to N
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

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

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible