Lecture 69: Print N-bit binary numbers having more 1s than 0s

preview_player
Показать описание


Day 96/180, #180daysofcode #180 hard

We are doing 180 days challenge and going to complete the whole course within the duration with quality content on Youtube. I am on the mission to create a tech revolution in our country and in upcoming future we want to create a tech which will create many jobs in India.

Video will come on Mon-Fri at 6am in the morning

DSA Course for free
C++ Free Course
Rohit Negi DSA Course C++
Coder Army DSA Course c++
Function in C++
Pointers in C++.
Strings
Vector
Introduction to Recursion

Рекомендации по теме
Комментарии
Автор

New Year ke liye Ready hai aap... Baaki 500 Like ke Target ki Chamka do....

CoderArmy
Автор

solved in 1st attempt without seeing your solution... confidence is on top now... thanks for these amazing lectures.

rohitchauhan
Автор

bhaiya aap ham logo ke liya itna hard work kar rahe hai aur ham log like na kare aise possible nahi hai mai jaanta hu bhaiya 6 am morning me uthha kar video banana iske liya highest motivation ki jarurat hota hai
thankyou bhaiya for your contribution to me and our coder army's brothers

KahaniKeSathJivan
Автор

Sir, at the age of 35, though it is just a number, I also felt that I can do it. Please keep going and enlightened us. Hope to meet you someday.

sagardogra
Автор

One of the best recursion series i have seen on youtube.

demoDevv
Автор

mzaa aa gya bhaiya recursion ki baap level series.ab toh mai khud approach soach bhi leta hu aur code bhi kr deta hu aaj wala video ka question khud se solve kr liya bina video dekhe bhaiya

Noobiee_FPS
Автор

Bhaiya I was able to solve in the first try. Now watching this lecture to understand your approach. Thankyou for your amazing lectures. You are great <3

My Solution:

class Solution{
public:

void solve(int count0, int count1, string str, vector<string>&ans, int n){
if(count0 >count1){
return;
}


if(count1+count0 >= n){
ans.push_back(str);
return;
}

//add 0
solve(count0+1, count1, str+"0", ans, n);


//add 1
solve(count0, count1+1, str+"1", ans, n);
}




vector<string> NBitBinary(int n){

string str = "1";
vector<string>ans;

int count0=0;
int count1=1;

solve(count0, count1, str, ans, n);

sort(rbegin(ans), rend(ans));

return ans;
}
};

study-ydes
Автор

Bhaiya Maja aayegaa jab aapne bola apne se pehle try karo-
To uske baad Maine try Kiya aur mere se ban gaya third chance mai .
Mujhe isse confidence bahut Mila .
Aur mujhe apni galti bhi samajh aaya me suru mai kya galat lik rha tha code.
Thank you bhaiya

Harsh-mybr
Автор

Heartfelt thanks and regards for such tireless teaching and clear explanation..chamak gya, Bhaiya

samriddhahalder
Автор

bhaiya khud se ho gaya this problem is similar to generate parenthesis thank you so much bhaiya

Akashkumar_
Автор

this problem is same as the generate paranthesis lecture 61 but little bit modification....
chamak gaya bhaiya....

RJFF-rw
Автор

I never thought that I would be able to solve these type of questions by my own, thanks a ton bhaiya, going ahead with you :)

vanshvadhwa
Автор

Recursion End Here... Literally this was Baap Level series🔥 Thank You Bhaiya❤

Gyanendra
Автор

BOTH VIDEO QUESTION AND HOMEWORK DONE ON MY HATSOFF TO YOUR TEACHING BHAIYYA

Pranav_
Автор

Tq bhaiya, chamak gya aur maja bhi aa gya 😄😄

saitanush
Автор

i did it bhaiya.

void BinaryBits(vector<string>&ans, string str, int count_One, int n){

if(count_One<0){
return;
}

if(str.size()==n){
ans.push_back(str);
return;
}
BinaryBits(ans, str+'1', count_One+1, n);
BinaryBits(ans, str+'0', count_One-1, n);


}
class Solution{
public:
vector<string> NBitBinary(int n)
{
// Your code goes here
vector<string>ans;
string str;
BinaryBits(ans, str, 0, n);

return ans;
}
};

abhishekkatiyar
Автор

bhaiya solved by my own thanks for your great teaching.

suryxnz
Автор

❤‍🔥
Home Work*
// N Bit Binary Number condition No of 1 >=No Of 0
#include <iostream>
#include <vector>
using namespace std;
void find(vector<string>&ans, string &temp, int zero, int one, int N){
if(temp.size()==N){
ans.push_back(temp);
return;
}
temp.push_back('1');
find(ans, temp, zero, one+1, N);
temp.pop_back();
if(zero<=one && temp[0]=='1'){
temp.push_back('0');
find(ans, temp, zero+1, one, N);
temp.pop_back();
}
}
int main() {
int N=4;
string temp;
vector<string>ans;
find(ans, temp, 0, 0, N);
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<endl;
}
}

Pallab
Автор

that's amazing, maine khud kr liya ye question 🤞✌

foodieswala
Автор

Chamak Gaya bhaiya sab ❤❤ best part is rat in maze problem

SiyaRamSiyaRam
welcome to shbcf.ru