Print N-bit binary numbers having more 1s than 0s GFG POTD Python Solution

  Рет қаралды 236

VS Code

VS Code

Ай бұрын

Problem - www.geeksforgeeks.org/problem...
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 1:
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".
Example 2:
Input:
n = 3
Output:
"111, 110, 101"
Explanation: Valid numbers are those where each prefix has more 1s than 0s.
111: all its prefixes (1, 11, and 111) have more 1s than 0s.
110: all its prefixes (1, 11, and 110) have more 1s than 0s.
101: all its prefixes (1, 10, and 101) have more 1s than 0s.
So, the output is "111, 110, 101

Пікірлер: 5
@Elitefootball5010
@Elitefootball5010 Ай бұрын
Thanks for uploading daily🎉
@vibhutigaharwar1
@vibhutigaharwar1 Ай бұрын
😊
@joymondal8321
@joymondal8321 Ай бұрын
@vibhutigaharwar1
@vibhutigaharwar1 Ай бұрын
thanks😊
5 Uncommon Python Features I Love
15:09
Indently
Рет қаралды 111 М.
Compiled Python is FAST
12:57
Doug Mercer
Рет қаралды 73 М.
◆テンゲテンゲダンス~Tengelele~◆ #ひめちゃんとおうくん #funny #shorts
00:24
プリンセス姫スイートTV Princess Hime Suite TV
Рет қаралды 20 МЛН
WWE is real💔
00:16
IShowSpeed
Рет қаралды 83 МЛН
He FOUND MYSTERY inside the GUMMY BEAR 😱🧸😂 #shorts
00:26
BROTHERS VLOG
Рет қаралды 52 МЛН
Which one will take more 😉
00:27
Polar
Рет қаралды 17 МЛН
Why You Should AVOID Linked Lists
14:12
ThePrimeTime
Рет қаралды 264 М.
STOP Using Plain Python Scripts! Do this instead (5 reasons)
15:47
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 415 М.
A Simpler Way to See Results
19:17
Logan Smith
Рет қаралды 89 М.
Introduction to Programming & Python | Python Tutorial - Day #1
11:50
CodeWithHarry
Рет қаралды 5 МЛН
C Program to Check a Number is Odd or Even | Learn Coding
8:11
Learn Coding
Рет қаралды 129 М.
Python Generators Explained
28:37
Tech With Tim
Рет қаралды 139 М.
Java Collections Explained (with examples)
10:39
Visual Computer Science
Рет қаралды 61 М.
◆テンゲテンゲダンス~Tengelele~◆ #ひめちゃんとおうくん #funny #shorts
00:24
プリンセス姫スイートTV Princess Hime Suite TV
Рет қаралды 20 МЛН