• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
March 26, 2024 |730 Views
PROBLEM OF THE DAY : 25/03/2024 | Print N-bit binary numbers having more 1s than 0s
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Bit Manipulation but also build up problem-solving skills.

In this problem, we are given a positive integer n. Your task is to generate a string list of all n-bit binary numbers where, for any prefix of the number, there are more or an equal number of 1's than 0's. The numbers should be sorted in decreasing order of magnitude.

Example :

Input:  
n = 2
Output: 
"11, 10"
Explanation: Valid numbers are those where each prefix has more 1s than 0s:
11: all its prefixes (1 and 11) have more 1s than 0s.
10: all its prefixes (1 and 10) have more 1s than 0s.
So, the output is "11, 10".

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/print-n-bit-binary-numbers-having-more-1s-than-0s0252/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp14-compiler/824fa874-1d2d-4310-ba99-2e6663ce8c07

Read More