Easy pisy❤😅 Int num = (start xor goal) Int cnt = 0; while(num) { num &= (num - 1) ; cnt++; } return cnt;
@ashurajput69164 ай бұрын
int differ = start^end; return __builtin_popcount(differ); ; )
@ThePROestRedn993 ай бұрын
@@ashurajput6916😂😂 op
@Shantisingh-tz5sr8 ай бұрын
int bitmask=(1
@aswin62619 ай бұрын
Most anticipated one❤
@i8you9 ай бұрын
long awaited video finally ❤
@rahulsangvikar79739 ай бұрын
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
@theangaarbatchbynamansharm26229 ай бұрын
Code readibility😢
@yunik_developer7 ай бұрын
Yup
@CodewithAnuragBassu9 ай бұрын
keep it up bhaiya and thanku so much🙏🙏🙏🙏
@diyatoliya90675 ай бұрын
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; }
@sumitdon20044 ай бұрын
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; } };
@ansariaburehan2632 күн бұрын
Love it. THank you sir.
@rohitchakraborty46197 ай бұрын
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!!
@HaamroNotes7 ай бұрын
i also did the same bro
@shubhrajit21176 ай бұрын
Same pinch! But why did u create new variables a and b?
@rohitchakraborty46196 ай бұрын
@@shubhrajit2117 actually striver once said never mess with the original variables just a good practice of mine
@HarshKumar-mx9nj5 ай бұрын
@@shubhrajit2117 its good practice to not alter the data given as the test case
@codesetter24974 ай бұрын
I also done same
@DeadPoolx17122 ай бұрын
UNDERSTOOD;
@UECAshutoshKumar8 ай бұрын
Thank you 😊
@ANKAMJANAKIRAM2 ай бұрын
The way striver blushes when calling *" 13 "*.... May it's our bhabhi favourite 😅
@pratyushtripathi17282 ай бұрын
Understood++++ 😁
@shahidullahmuffakir6685 ай бұрын
done and dusted😃❤
@spartannng3 күн бұрын
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; }
@dayashankarlakhotia49439 ай бұрын
public int minimumBitFlip(int start,int goal){ int val=start^goal,cnt=0; while(val>0){ val&=val-1; cnt++; } return cnt;
@riteshbisht948 ай бұрын
Make more lectures 🙏🥺
@bthulasikrishna95973 ай бұрын
Python one liner return bin(start^goal)[2:].count('1')
@ishwarreddy88209 ай бұрын
Very helpful .
@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); } };
@SibiRanganathL4 ай бұрын
Understood🤗🤗🤗🤗
@DeepakPatel-d5v7 ай бұрын
Thanks a lot Bhaiya
@khalasianiket8165 ай бұрын
understood ❤
@navinchaudhary28129 ай бұрын
understood
@vishnupandey33904 ай бұрын
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)
@bthulasikrishna95973 ай бұрын
print(bin(start^goal)[2:].count('1'))
@pratulyapratap93299 ай бұрын
God 🙏
@khyatikakkar9259Ай бұрын
C++ one liner class Solution { public: int minBitFlips(int start, int goal) { return __builtin_popcount(start^goal); } };
@Learnprogramming-q7f8 ай бұрын
thank you Bhaiya
@hakunamatata-nl4js6 ай бұрын
Thank you
@shashankgsharma09015 ай бұрын
Understood!
@shikher45594 ай бұрын
great!
@animeshkumar26833 ай бұрын
Understood
@vkgaming33164 ай бұрын
One line solution would be return __builtin_popcount(start^goal); 😅
@manyachandra35663 ай бұрын
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Ай бұрын
while (number > 0) { bit += (number & 1); number >>= 1; }
@Bob_Celestine9 ай бұрын
❤❤❤❤❤❤❤❤❤
@eshuthakur29826 ай бұрын
Can someone plz tell where to get this code
@tamannaverma41789 ай бұрын
🙌
@anshsaxena72973 ай бұрын
UnderStood
@adityapandey232 ай бұрын
Understood
@saurabhdwivedi28319 ай бұрын
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; }