Тёмный

Print N-bit binary numbers having more 1’s than 0’s for any prefix 

Aditya Verma
Подписаться 253 тыс.
Просмотров 70 тыс.
50% 1

Опубликовано:

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 279   
@ntesla5
@ntesla5 4 года назад
Thank you very much for awesome explaination . Most of the comment section of his all videos are usually requesting for different topics or correcting or asking for some sort of help. We all are so selfish , the guy is teaching (BEST in the world) and that to for free of cost. Despite getting a high salary job , he is still spending his value able time for us . I think we should accept it and appreciate his work and not force him to make video based on our requirements
@TheAdityaVerma
@TheAdityaVerma 4 года назад
❤️❤️❤️❤️❤️❤️❤️❤️
@akashmanna2099
@akashmanna2099 4 года назад
Nailed it 👌!
@akshatw7866
@akshatw7866 3 года назад
Exactly my thoughts!
@ADNANAHMED-eo5xx
@ADNANAHMED-eo5xx 3 года назад
@@TheAdityaVerma isi baat par video daal do yaar
@ayushmansingh5271
@ayushmansingh5271 3 года назад
@@ADNANAHMED-eo5xx 😂
@shrihariprajapati9996
@shrihariprajapati9996 3 года назад
Coded it on my own within 15 mins ! And just a week ago I couldn't even understand how recursion works ! Thanks man ! Legend ! 🙌
@nirmalwagh1976
@nirmalwagh1976 3 года назад
Can u please share code?
@aniketbhoite7168
@aniketbhoite7168 3 года назад
Initially add 1 in output string n pass no of zero as 0 n one as 1 n as n-1....then if o>z then we can add one or zero otherwise only one... Hope this helps
@AmarSingh-qj1pp
@AmarSingh-qj1pp 3 года назад
Hey can you solve the generating m bit gray code of gfg using recursion. I have been trying it but stuck on one test case. If possible pls do
@thinkingmad1685
@thinkingmad1685 3 года назад
Like did u code in ide with problem statement or just own ide
@Monkeydluffy-we2fk
@Monkeydluffy-we2fk 2 года назад
Ha maine bhi ..recursion ka master hu mai abh 😶..lol agle video dekhna hai cuz there
@satwikmishra60
@satwikmishra60 3 года назад
Trust me, this guy's a living legend. Just a month ago I couldn't even write a single line of code for a basic recursion problem and eventually ended up doing this question just after hearing the problem statement. 🎩📴
@piyushgupta9048
@piyushgupta9048 4 года назад
I was able to solve recursion questions but after this, I m able to solve problems in much lesser time. These videos gave me immense clarity on how to approach a question.
@Ak-.-47
@Ak-.-47 3 года назад
Before Watching this series I was not able to approach basic problems of recursion....but now due to Your help i am easily able to do medium level questions.Thanku sir for this❤
@priyankarai7005
@priyankarai7005 4 года назад
did it myself. now going to look at solution. Thank u so much aditya
@manavshah7450
@manavshah7450 3 года назад
Watch the video till 12:19 and then code the solution yourself. You will definitely get it! Thank you aditya verma for all this. You are the best!
@swappy4515
@swappy4515 3 года назад
Yess I did the same
@Ssss-ox2nu
@Ssss-ox2nu 3 года назад
yes same me too
@sunnykumarjha9527
@sunnykumarjha9527 2 года назад
same vro😁 yar itna aasan bana diya hai bhai ne recursion ko😂
@AkashKumar-lr6hc
@AkashKumar-lr6hc 2 года назад
I did just by reading question ... He made me Jedi in recursion
@HimanshuSingh-yh8lz
@HimanshuSingh-yh8lz 3 года назад
before starting this series I was having problem while solving problems of recursion and now I am solving the question before watching the explanation video..Thanks, Aditya Verma
@DroidHolicOfficial
@DroidHolicOfficial 2 года назад
Wow! You have explained previous problems so damn well that I didn't even have to watch this video to write the solution. Thanks a lot man!
@viditshah5944
@viditshah5944 4 года назад
Sir Awesome videos.This might be No.1 channel to prepare and clear the concepts... It gives too much bust for interview preparation..! Waiting for Backtracking problems..
@darkndown
@darkndown Год назад
I, just like others in comments, wasn't able to write basic recursive code. However, after watching this playlist, I coded this ques just after hearing the problem statement. Thanks Aditya!
@ankitmishra3823
@ankitmishra3823 3 года назад
I saw all series of recursion and able to do question very easily and able to understand problems.
@abhijitsaha4311
@abhijitsaha4311 3 года назад
You are great brother. I am one of those CS student who always preferred maintaining a safe distance from recursion. As a result I was getting feverish feeling whenever I was facing problems that need DP to solve. I came across your DP playlist first and after watching a few videos I felt if anyone can teach me Recursion, it is Aditya Verma only. Now I am solving problem before looking into your solutions. You are just a gift of GOD. Stay healthy and happy brother. Keep teaching us with your amazing teaching skills.
@sumitkeshav4718
@sumitkeshav4718 4 года назад
A few moments later 😂😂! Great content as usual ❤✌
@AnupBarman-bd1ju
@AnupBarman-bd1ju 4 месяца назад
coded it on my own again! the basics I've received from this playlist is unimaginable. hats off bhai.
@AnupBarman-bd1ju
@AnupBarman-bd1ju 4 месяца назад
the code i've written for the gfg problem is here : class Solution{ public: void generate(int n, int one, int zero, string op, vector &v) { if (n == 0) { v.push_back(op); return; } if (n != 0) { string op2 = op; op2.push_back('1'); generate(n - 1, one + 1, zero, op2, v); } if (one > zero) { string op2 = op; op2.push_back('0'); generate(n - 1, one, zero + 1, op2, v); } return; } vector NBitBinary(int n) { vector v; string op = ""; generate(n, 0, 0, op, v); sort(v.begin(), v.end(), greater ()); return v; } };
@ajitpawar7558
@ajitpawar7558 2 года назад
I was fearing the recursion. Whenever i saw recursion i tried to do it with loops but never got the answer in required time complexity. At the starting of the series he said that after completing the entire playlist you will become Jedi. And yes after completing i can say i have become Jedi in Recursion. Thanks a lot for helping me out. You are doing a great job here.... ❤️💯🔥
@Cool-ss7ph
@Cool-ss7ph 8 месяцев назад
Solved this question in 5 min, even before watching it, just on the basis of the knowledge gained from the previous videos in the playlist. Great work man.. hats off to you. 👏👏👏
@saloni8603
@saloni8603 3 года назад
Can't thank you enough for this awesome playlist 😭❤❤
@shivambhardwaj5313
@shivambhardwaj5313 2 года назад
about to finish this playlist just one more question left, normally i dont even have to watch your complete video thanks to your explanation. thanks a lot hope u return to youtube
@rajshreebose1828
@rajshreebose1828 2 года назад
God Bless you, Buddy!!! was struggling with recursion since months now.
@hope-jh7bv
@hope-jh7bv 2 года назад
Thank you so much sir. With your help I am so much confident with recursion and backtracking. I was so depressed and having second option other than learning DSA. But finally I am able to solve medium range problems gradually and got my confidence back. I will be always grateful to you. Again, thanks a lot.
@himanshumalik6913
@himanshumalik6913 2 года назад
Bhai, khud se kar lya sirf shuru ke 15 min video dekhi, question understand ke lye. Bina answer dekhe 😭😭😭😭😭 Thank you bhai.
@harshitpatil6138
@harshitpatil6138 7 месяцев назад
Just click on video saw first 10 sec and think let me understand myselft about ip-op and ps click on the link and understand the problem then first try to make the recursive tree ofcourse first time I failed to do . then again think about the problem and retry to build the recursive tree and this time somehow I made it and see what I code it as you taugh once you made a recursive writing code will be cake work . so I just run code again test case and it passes😄 that is the power of your teaching . Thankyou aditya Bhaiya for your efforts ! You are The BEST 🙃.
@archanaa7747
@archanaa7747 2 года назад
tysm for this playlist. you explained each and everything very clearly. this playlist help me a lottt.
@rajeshramoju8837
@rajeshramoju8837 3 года назад
just saw the problem statement and boom i did myself ..thankyou
@saravind3153
@saravind3153 3 года назад
We need your tutorials sir big fan of you
@anshirk9770
@anshirk9770 3 года назад
11 minutes was sufficient due to your amazing explanation! Thank you so much bhaiyya :')
@SKILLCRYSTAL
@SKILLCRYSTAL 2 года назад
The best about his videos is that after you watched the explanation of the problem, you can code by yourself irrespective of which language you code.
@sarvagyaiitmadras8727
@sarvagyaiitmadras8727 3 года назад
really awesome content.Only one problem in videos me , voice thodi low rhti hai bhai tumhari, mtlb full audio krne pe bhi.
@SHAH_SSC
@SHAH_SSC Год назад
i was literally able to solve this question on my own in the first go...all thanks to your efforts bro..( this playlist is must for everyone who thinks recursion sucks.)
@LokeshSharma-hm5jz
@LokeshSharma-hm5jz Год назад
Watching previous videos, the moment you said it is related to balanced parenthesis. I got the idea. Thanks
@vanshjain5960
@vanshjain5960 Год назад
I am wordless how good ur content is this is just awesome bhaiiii Love it❤❤❤❤❤❤
@shubhamkumarjha2653
@shubhamkumarjha2653 2 года назад
Thanks a lot buddy .😍 Just week ago I can't able to solve simple prb but know I have lot of confidence .
@ved7678
@ved7678 4 года назад
Thanks a lot bro for your effort. It's been a great help for me. Just a request can you please make videos on Greedy,backtracking and divide & conqueror
@shaikfahim1232
@shaikfahim1232 3 года назад
Include graph also
@aayushpagare9366
@aayushpagare9366 3 года назад
OMG Aditya bhaiya you are magical.....i cant belive i came with the solution in just 5 minutes......TQSM ❤️❤️❤️❤️
@adityajain5101
@adityajain5101 2 года назад
Your explanation is best ...better than most of the youtubers out there
@DebojyotiMandal
@DebojyotiMandal 4 года назад
Best playlist on recursion ever !!!!!!
@vineeladonthu9266
@vineeladonthu9266 3 года назад
Thank you so much sir! the way you taught us to approach the problem is very good sir
@aniketpathak2721
@aniketpathak2721 3 года назад
Amazing work bhaiya! Hands down, one of the best channel to learn algorithms. Will always be grateful for what I gained from this channel!
@dewanganumesh11
@dewanganumesh11 4 года назад
Thanks @AdityaVerma....now i can realized how to approach for recursive problem. Keep up the good work :)
@subrinasirajee530
@subrinasirajee530 3 года назад
Coded on my own way without seeing the full video. Thanks bro.
@mohit6215
@mohit6215 Год назад
I was able to think about it by yours grace❤
@zaidshaikh8111
@zaidshaikh8111 2 года назад
I watched first two mins and solved the question!!! Aditya Bhaiyya, You are amazing!!!
@mayur_madhwani03
@mayur_madhwani03 3 года назад
Itna sahi samjhaya ki khudse hi code likh liya ❤️
@kushgupta6416
@kushgupta6416 2 года назад
I really liked your way of teaching and keep on building problems based on previous thinking. it helps a lot to grasp concepts. just one suggestion. try to provide a few examples of a problem that requires for loop along with recursion. like print all permutation of array elements.
@codertan4109
@codertan4109 2 года назад
Thank You so much Aditya! I was able to code by myself!!!
@LokeshSharmaCP
@LokeshSharmaCP 8 месяцев назад
thanks a lottttt solving recursion que - medium, hard easily after this
@shishirchaurasiya7374
@shishirchaurasiya7374 Год назад
Aditya Verma OP!!!!!! Love you so much..
@mayureebudhe5087
@mayureebudhe5087 3 дня назад
You are Kohinoor Boss, amazing skills you have. Take a Bow
@aashimaa2681
@aashimaa2681 2 года назад
Thanks Adi! You are the best
@tiyashadas5247
@tiyashadas5247 3 года назад
I solved a recursion problem on my own :') im not crying you are crying :') Thank you :') 🌻
@amayatre3558
@amayatre3558 2 года назад
Thank you so much Bhaiya , because after following this playlist completely , I was able to solve this question just by reading the problem statement. Hats Off to you Bhaiya ..
@shibanidas7018
@shibanidas7018 3 года назад
Finished without seeing the solution !!! public void generate(String op, int n0, int n1, int N, ArrayList list){ if(n0 + n1 == N){ list.add(op); return; } String op1 = op + "1"; generate(op1, n0, n1-1, N , list); if(n0 > n1){ String op2 = op + "0"; generate(op2,n0-1,n1,N,list); } }
@harshitewari
@harshitewari 4 месяца назад
As base condition if we take zeroes + ones = n; then we get a segmentation fault. Does anyone know why this happens?
@vikasvk9174
@vikasvk9174 4 года назад
After looking at the problem statement. I solved it myself it only happen bcz of You Big Thank :)
@priyanjali2857
@priyanjali2857 2 года назад
Thank you so much for the recursion playlist FINALLY I UNDERSTOOD THE CONCEPT Also please could you also make videos on backtrackingggg Thanks dude!!!!
@khushh.i
@khushh.i 4 месяца назад
Sir, thank youuuuuuuu soooo much!!!!!!!
@ayanjana2052
@ayanjana2052 2 года назад
Thanks for the awesome explanation
@Playlist-cj9ct
@Playlist-cj9ct 5 месяцев назад
I tried this, is it fine or should I change my approaches? function printBit(n,i,ans,p,q){ if(p>q){ return } if(i===n){ console.log(ans) return } printBit(n,i+1,ans+'0',p+1,q) printBit(n,i+1,ans+'1',p,q+1) } printBit(4,0,'',0,0)
@dhirunand
@dhirunand 2 года назад
Watched video till 9:50 and coded it, love you brooooo 😍
@Vishal-ds6ly
@Vishal-ds6ly Год назад
thankyou very much sir for awesome playlist on recursion
@parthmittal5625
@parthmittal5625 3 года назад
Solved on my own!! Unmatched playlist! 🙇🏼‍♂️
@keshavbiyani9202
@keshavbiyani9202 7 месяцев назад
Another base condition could be if n0+n1 == n We won't have to reduce n Here's the python code """ For an input N, print the total number of n bit binary numbers for which, the number of 1's in all the prefixes is greater than or equal to number of 0's 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". """ from typing import List def getAllNBitBinaryNumbers(allNBitBinaryNumbers:List[str], n0:int, n1:int, op:str, N:int): if n0 + n1 == N: allNBitBinaryNumbers.append(op) return op1 = op + "1" getAllNBitBinaryNumbers(allNBitBinaryNumbers, n0, n1+1, op1, N) if n1 > n0: op2 = op + "0" getAllNBitBinaryNumbers(allNBitBinaryNumbers, n0+1, n1, op2, N) if __name__ == "__main__": n = int(input("Number of bits needed ins string ? ")) allNBitBinaryNumbers = [] n0 = 0 n1 = 0 op = "" getAllNBitBinaryNumbers(allNBitBinaryNumbers, n0, n1, op, n) print(allNBitBinaryNumbers) Please let me know if there are any suggestions on improvement :) Thanks for the teachings Aditya
@shantamshrestha2070
@shantamshrestha2070 4 года назад
Sir I think you missed questions on Longest Increasing Subsequence and it's variations in DP playlist. Those problems are tricky sometimes. Please discuss those as well
@laxmangurjar4776
@laxmangurjar4776 2 года назад
love the way you teach ❤
@mohit84604
@mohit84604 Год назад
javascript code function main (p){ let n = p let zero = 0 let one = 0 let op = "" solve(n,one,zero,op) } function solve(n,one,zero,op){ if(n == 0){ console.log(op) return } if(one == zero){ let op1 = op + "1" solve(n - 1,one + 1,zero,op1) }else if(one > zero){ let op1 = op + "1" let op2 = op + "0" solve(n - 1,one + 1,zero,op1) solve(n - 1,one,zero + 1,op2) } } main(5)
@bhairavas2528
@bhairavas2528 3 года назад
Java Solution. A bit different from Aditya's approach public static void solve(int one,int zero,int n,String output) { if(n==0) { System.out.println(output); return; } if(one == zero) { String op1 = output; op1+="1"; solve(one+1,zero,n-1,op1); }else { String op1 = output; String op2 = output; op1+="1"; op2+="0"; solve(one+1,zero,n-1,op1); solve(one,zero+1,n-1,op2); } }
@panavkumar9009
@panavkumar9009 2 года назад
I can't believe I was able to solve this problem on my own!!
@aritralahiri8321
@aritralahiri8321 4 года назад
Your work is really great . No one has ever taught recursion in the same manner you are teaching .You are teaching us how to use a tool so that it can be used whenever necessary .I can say now that I really know recursion , I've solved this problem without looking into your solution . Really grateful for this hard work really appreciate your work bro . Thanks a lot .
@shyampramanik780
@shyampramanik780 4 года назад
Great content as always !!
@Prateek_Mantry
@Prateek_Mantry 6 месяцев назад
thank you.
@ManishKumar-ux5un
@ManishKumar-ux5un 3 года назад
@Aditya sir you can use pointer mark so that we can see where you are pointing.
@PriyanshuSingh-dt3oz
@PriyanshuSingh-dt3oz 2 года назад
you deserve 1 million subscribers.🙇🙇
@sureshgadde5113
@sureshgadde5113 4 года назад
Thank you Bhai, for such a great explanation
@RohitGupta-fv1ul
@RohitGupta-fv1ul 4 года назад
Eagerly Waiting for graph contents
@devgupta9469
@devgupta9469 4 года назад
Please make videos on graph. I keep forgetting its algorithms
@aryachaudhary1118
@aryachaudhary1118 3 года назад
``` int n; void bin(string s , int o , int z) { if(o+z==n) { cout
@tushargarg3765
@tushargarg3765 2 года назад
# Running code n=3 def solution(ones,zeros,output,ans): if ones+zeros==n: print(output) ans.append(output) return if ones
@pandalove5374
@pandalove5374 4 года назад
Great explanation. Can you please let us know if we can expect new videos on Dp playlist(Fibonacci, Lis and kadane’s algo)
@thread1066
@thread1066 7 месяцев назад
python code : def gen(op,one,zero,n): if n==0: print(op) return if op=='': op = op + "1" gen(op,one+1,zero,n-1) elif one > zero: op2 = op +"1" gen(op2,one+1,zero,n-1) op1 = op + "0" gen(op1,one,zero+1,n-1) else: op = op + "1" gen(op,one-1,zero,n-1) op = '' n = 3 one = zero = 0 gen(op,one,zero,n)
@arijitchandra8218
@arijitchandra8218 4 года назад
thank u for uploading videos like this
@gulshankumar9118
@gulshankumar9118 4 года назад
Koi bat nhi bhai jo ha wo bhi ek no. hai......
@TheAdityaVerma
@TheAdityaVerma 4 года назад
Thanks brother, making videos is easy, but dealing with these issues (hissing sound/low audio) is really a headache 😓😓Now I know how hard these other quality youtubers work.
@gulshankumar9118
@gulshankumar9118 4 года назад
@@TheAdityaVerma keep it up!! brother.......u will find a sol^n.....u could take help of other youtubers too.....
@viggicodes
@viggicodes Год назад
def solve(zero, one, op, n): if zero+ one == n: print(op) return if one > zero: op1 = op + "0" solve(zero+1, one, op1,n) op2 = op + "1" solve(zero, one + 1, op2,n) return solve(0, 0, "", 3)
@aakash4771
@aakash4771 2 года назад
cpp code //Print N-bit binary numbers having more 1’s than 0’s for any prefix #include using namespace std; void solve(string output,int one ,int zero,int n){ if(n==0){ cout
@ShivangiShree
@ShivangiShree 4 года назад
You are back❤
@atrikha40
@atrikha40 2 года назад
Thanks for the videos. Learning a lot from them. Had one question, I tried it on my own before starting the video. Had one doubt. Do you think 1 will always be prioritized when #0 == #1. This is how I wrote in Swift. func solve(_ out: String, _ zero: Int, _ one: Int, _ n: Int) { if n == 0 { print(out) return } if zero == one { // When zero and 1 both are same then we need to give preference to 1 let op1 = "\(out)1" solve(op1, zero, one+1, n-1) } if zero < one { let op1 = "\(out)0" let op2 = "\(out)1" solve(op1, zero+1, one, n-1) solve(op2, zero, one+1, n-1) } return } let n = 5 solve("1", 0, 1, n-1) Result: 10101 10110 10111 11001 11010 11011 11100 11101 11110 11111 Please let me know your thoughts!
@aniketbhoite7168
@aniketbhoite7168 3 года назад
Thank you...we can literally solve these problems with nearly same functions...just little bit change n no need to see the video as well
@bhumikasharma5033
@bhumikasharma5033 3 года назад
Great explanation
@sohel-tamboli
@sohel-tamboli 4 года назад
Thank You So much bro for this playlist it is really improving my problem solving skills. Because of You, I am able to solve last parenthesis and this problem and other many problems without seeing Logic . Thank You So Much For great video series......
@krishparmar7917
@krishparmar7917 Год назад
awesome video bro 💙💙. pr saath me time complexity bhi bta diya kr.
@randomthoughts3533
@randomthoughts3533 4 года назад
Hey Adi did it again thanx to you buddy
@UCS_B_RishiRajTiwari
@UCS_B_RishiRajTiwari 2 года назад
Awesome Content... Now recursion has become cakewalk for me...
@codewithsachendra7090
@codewithsachendra7090 4 года назад
Waiting for backtracking😍
@SaurabhSingh-ph2ry
@SaurabhSingh-ph2ry 3 года назад
But haven't got 🥲
@animeshbarole
@animeshbarole 2 года назад
Code with my Own ,Thnx Man
@gamerhu7462
@gamerhu7462 3 года назад
i did it myself yaass Yaar ye banda kitna awesome hai!!
@chetanpandey8722
@chetanpandey8722 3 года назад
void solve(int n, string res, vector &vec, int ones=0, int zeros=0){ if(n == 0){ if(ones>=zeros){ vec.push_back(res); } return; } solve(n-1, res+"1", vec, ones+1, zeros); if(!res.empty()) solve(n-1, res+"0", vec, ones, zeros+1); } vector NBitBinary(int N) { // Your code goes here string str; vector st; solve(N, str, st); return st; } I was trying this for the above question but its giving output limit exceeded. Can someone suggest where I am going wrong
@ManishKumar-ux5un
@ManishKumar-ux5un 3 года назад
@Aditya sir phle binary search mei hin audio kaafi shi tha ...please use good device.
@NitinKumar-pl3xl
@NitinKumar-pl3xl 4 года назад
Thanks Bro for doing this from your heart with one goal to help others. You are doing without any expectation from others. Follow this attitude/simplicity using pen and paper, definitely you will get what you want in life. The good thing is that you are not wasting time in basics(definition etc) the way or approach you are building to solve problem is awesome. Below list is considered as best material for Data Structure and Algorithm there is no comparison of your videos to this. Even your videos are very help full for experience ones also they have to also face first coding round. 1. Cracking the Coding Interview, 6th Edition :Gayle Laakmann McDowell 2. Introduction to Algorithms Third Edition : Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein 3. RU-vid video : Abdul Bari If possible add English subtitles. After that you can see the difference in your video will reach to world wide. Subscribed your channel.
@neymarjr-sc3oi
@neymarjr-sc3oi 4 года назад
JAVASCRIPT SOLUTION function subset(n,one,zero,arr){ if(n==0){ console.log(arr); return; } subset(n-1,one+1,zero,arr+'1'); if(one>zero){ var arr2=arr; var n2=n; subset(n2-1,one,zero+1,arr2+'0'); }; return; } var no=3; var o=0; var z=0; var ar=''; subset(no,o,z,ar);
@samadahmed571
@samadahmed571 3 года назад
my approach(java): static void bin(int sum,int n,String op) { if(n==0) { System.out.print(op+" "); return; } String op1=op; String op2=op; //no. of one==no of zeroes,sum==0 if(sum==0) { op+=Character.toString('1'); bin(sum+1,n-1,op); } //no. of one>no. of zeroes else if(sum>0) { op1+=Character.toString('1'); op2+=Character.toString('0'); bin(sum+1,n-1,op1); bin(sum-1,n-1,op2); } }
@gokusaiyan1128
@gokusaiyan1128 2 года назад
# Print N-bit binary numbers having more 1’s than 0’s for any prefix res = [] def generate(output, ones, zeroes, n): if n == 0: res.append(output) return else: if ones == zeroes: generate(output + "1", ones+1, zeroes, n-1) elif ones > zeroes: generate(output + "1", ones+1, zeroes, n-1) generate(output + "0", ones, zeroes+1, n-1) n = 5 ones = 0 zeroes = 0 generate("", ones, zeroes, n) print(res)
Далее
Generate all Balanced Parentheses
34:03
Просмотров 148 тыс.
Permutation with spaces
21:11
Просмотров 87 тыс.
5 01 Knapsack Top Down DP
41:08
Просмотров 611 тыс.
11 N Digit numbers with digits in increasing order
32:24
Kth Symbol in Grammar
23:32
Просмотров 124 тыс.