L3. Minimum Bit Flips to Convert Number | Bit Manipulation

  Рет қаралды 69,201

take U forward

take U forward

Күн бұрын

Пікірлер: 60
@faizanalam8823
@faizanalam8823 9 ай бұрын
Easy pisy❤😅 Int num = (start xor goal) Int cnt = 0; while(num) { num &= (num - 1) ; cnt++; } return cnt;
@ashurajput6916
@ashurajput6916 4 ай бұрын
int differ = start^end; return __builtin_popcount(differ); ; )
@ThePROestRedn99
@ThePROestRedn99 3 ай бұрын
​@@ashurajput6916😂😂 op
@Shantisingh-tz5sr
@Shantisingh-tz5sr 8 ай бұрын
int bitmask=(1
@aswin6261
@aswin6261 9 ай бұрын
Most anticipated one❤
@i8you
@i8you 9 ай бұрын
long awaited video finally ❤
@rahulsangvikar7973
@rahulsangvikar7973 9 ай бұрын
I think it would have been much better to use n&(n-1) to count set bits, because if we're doing this, this is no different than doing count += (start&(1
@theangaarbatchbynamansharm2622
@theangaarbatchbynamansharm2622 9 ай бұрын
Code readibility😢
@yunik_developer
@yunik_developer 7 ай бұрын
Yup
@CodewithAnuragBassu
@CodewithAnuragBassu 9 ай бұрын
keep it up bhaiya and thanku so much🙏🙏🙏🙏
@diyatoliya9067
@diyatoliya9067 5 ай бұрын
int minBitFlips(int start, int goal) { int count=0; while(start!=goal){ if(start%2 != goal%2){ count++; } start=start>>1; goal=goal>>1; } return count; }
@sumitdon2004
@sumitdon2004 4 ай бұрын
std::string num2Bin(int n) { if (n == 0) return "0"; std::string res = ""; while (n > 0) { res += (n % 2 == 1) ? '1' : '0'; n = n / 2; } std::reverse(res.begin(), res.end()); return res; } class Solution { public: int minBitFlips(int start, int goal) { string x = num2Bin(start); string y = num2Bin(goal); while (x.length() < y.length()) x = '0' + x; while (y.length() < x.length()) y = '0' + y; int g = x.length(); int cnt = 0; for (int i = 0; i < g; i++) { if (x[i] != y[i]) { cnt++; } } return cnt; } };
@ansariaburehan263
@ansariaburehan263 2 күн бұрын
Love it. THank you sir.
@rohitchakraborty4619
@rohitchakraborty4619 7 ай бұрын
Well I used a bit of different approach and just compared the bits linearly class Solution { public: int minBitFlips(int start, int goal) { int a = start; int b = goal; int ct=0; while(a>0 || b>0){ if((a&1)!=(b&1)) ct++; a=a>>1; b=b>>1; } return ct; } }; not so creative but still works. Have a good day!!
@HaamroNotes
@HaamroNotes 7 ай бұрын
i also did the same bro
@shubhrajit2117
@shubhrajit2117 6 ай бұрын
Same pinch! But why did u create new variables a and b?
@rohitchakraborty4619
@rohitchakraborty4619 6 ай бұрын
@@shubhrajit2117 actually striver once said never mess with the original variables just a good practice of mine
@HarshKumar-mx9nj
@HarshKumar-mx9nj 5 ай бұрын
​@@shubhrajit2117 its good practice to not alter the data given as the test case
@codesetter2497
@codesetter2497 4 ай бұрын
I also done same
@DeadPoolx1712
@DeadPoolx1712 2 ай бұрын
UNDERSTOOD;
@UECAshutoshKumar
@UECAshutoshKumar 8 ай бұрын
Thank you 😊
@ANKAMJANAKIRAM
@ANKAMJANAKIRAM 2 ай бұрын
The way striver blushes when calling *" 13 "*.... May it's our bhabhi favourite 😅
@pratyushtripathi1728
@pratyushtripathi1728 2 ай бұрын
Understood++++ 😁
@shahidullahmuffakir668
@shahidullahmuffakir668 5 ай бұрын
done and dusted😃❤
@spartannng
@spartannng 3 күн бұрын
int minBitFlips(int start, int goal) { int n=start^goal; int cnt=0; while(n>0){ if((n&1)==1) cnt++; n=n>>1; } return cnt; }
@dayashankarlakhotia4943
@dayashankarlakhotia4943 9 ай бұрын
public int minimumBitFlip(int start,int goal){ int val=start^goal,cnt=0; while(val>0){ val&=val-1; cnt++; } return cnt;
@riteshbisht94
@riteshbisht94 8 ай бұрын
Make more lectures 🙏🥺
@bthulasikrishna9597
@bthulasikrishna9597 3 ай бұрын
Python one liner return bin(start^goal)[2:].count('1')
@ishwarreddy8820
@ishwarreddy8820 9 ай бұрын
Very helpful .
@aviralgoel5709
@aviralgoel5709 Ай бұрын
class Solution { public: int numOfBits(int n) { int result = 0; for(int i = 0; i < 32; i++) { result += (n >> i) & 1; } return result; } int minBitFlips(int start, int goal) { int y = (start ^ goal); return numOfBits(y); } };
@SibiRanganathL
@SibiRanganathL 4 ай бұрын
Understood🤗🤗🤗🤗
@DeepakPatel-d5v
@DeepakPatel-d5v 7 ай бұрын
Thanks a lot Bhaiya
@khalasianiket816
@khalasianiket816 5 ай бұрын
understood ❤
@navinchaudhary2812
@navinchaudhary2812 9 ай бұрын
understood
@vishnupandey3390
@vishnupandey3390 4 ай бұрын
here is the python3 solution for this problem num1=int(input("Enter number : ")) num2=int(input("Enter Desired number : ")) diff=num1^num2 ans=0 while diff: diff=diff&(diff-1) ans+=1 print("You need",ans,"bit flips to convert",num1,"to",num2)
@bthulasikrishna9597
@bthulasikrishna9597 3 ай бұрын
print(bin(start^goal)[2:].count('1'))
@pratulyapratap9329
@pratulyapratap9329 9 ай бұрын
God 🙏
@khyatikakkar9259
@khyatikakkar9259 Ай бұрын
C++ one liner class Solution { public: int minBitFlips(int start, int goal) { return __builtin_popcount(start^goal); } };
@Learnprogramming-q7f
@Learnprogramming-q7f 8 ай бұрын
thank you Bhaiya
@hakunamatata-nl4js
@hakunamatata-nl4js 6 ай бұрын
Thank you
@shashankgsharma0901
@shashankgsharma0901 5 ай бұрын
Understood!
@shikher4559
@shikher4559 4 ай бұрын
great!
@animeshkumar2683
@animeshkumar2683 3 ай бұрын
Understood
@vkgaming3316
@vkgaming3316 4 ай бұрын
One line solution would be return __builtin_popcount(start^goal); 😅
@manyachandra3566
@manyachandra3566 3 ай бұрын
but if start is 1 0 10 xor with 0 1 1 1 then ans is 1101 as written by striver but 1 and 0 cant give 1 na after fliiping it should be 0 as per start
@rohanyadav101
@rohanyadav101 Ай бұрын
while (number > 0) { bit += (number & 1); number >>= 1; }
@Bob_Celestine
@Bob_Celestine 9 ай бұрын
❤❤❤❤❤❤❤❤❤
@eshuthakur2982
@eshuthakur2982 6 ай бұрын
Can someone plz tell where to get this code
@tamannaverma4178
@tamannaverma4178 9 ай бұрын
🙌
@anshsaxena7297
@anshsaxena7297 3 ай бұрын
UnderStood
@adityapandey23
@adityapandey23 2 ай бұрын
Understood
@saurabhdwivedi2831
@saurabhdwivedi2831 9 ай бұрын
int minBitFlips(int start, int goal) { int ans = start ^ goal; int cnt = 0; while(ans != 0){ ans = ans & (ans -1); cnt = cnt +1; } return cnt; }
@chiragbansod8252
@chiragbansod8252 8 ай бұрын
understood
@SitaRam-m1i
@SitaRam-m1i Ай бұрын
Understood
@pranavmisra5870
@pranavmisra5870 7 ай бұрын
understood
@hardikpatel352
@hardikpatel352 6 ай бұрын
understood
@shaiksoofi3741
@shaiksoofi3741 5 ай бұрын
understood
L4. Power Set | Bit Manipulation
12:38
take U forward
Рет қаралды 73 М.
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 29 МЛН
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 20 МЛН
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 673 М.
Minimum Bit Flips to Convert Number - Leetcode 2220 - Python
12:16
Sorting Algorithms Explained Visually
9:01
Beyond Fireship
Рет қаралды 555 М.
L7. Single Number III | Bit Manipulation
24:03
take U forward
Рет қаралды 60 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 719 М.
TLS Handshake Explained - Computerphile
16:59
Computerphile
Рет қаралды 569 М.
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 29 МЛН