Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4610 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 603 |

@akashverma4 | 363 |

@swastik8750 | 300 |

@nishunishuraj18 | 286 |

@surajmamgai | 264 |

@anks9013 | 222 |

@nayan2709 | 213 |

@burhanuddinbohra72 | 212 |

@realname | 203 |

@amank8975 | 203 |

@manmeetkaur18102000 | 202 |

Complete Leaderboard |

Given a number **N**. The task is to generate and print all **binary numbers with decimal values** from **1 to N**.

**Example 1:**

Input:N = 2Output:1 10Explanation:Binary numbers from 1 to 2 are 1 and 10.

**Example 2:**

Input:N = 5Output:1 10 11 100 101Explanation:Binary numbers from 1 to 5 are 1 , 10 , 11 , 100 and 101.

**Your Task:**

You only need to complete the **function **generate() that takes **N **as **parameter **and returns vector of strings denoting binary numbers.

**Expected Time Complexity :** O(N log_{2}N)

**Expected Auxilliary Space : **O(N log_{2}N)

**Constraints:**

1 ≤ N ≤ 10^{6}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Generate Binary Numbers

...