Instead of checking for equality of mask, we also do: 1. XOR of both the numbers. 2.Do mask with XOR value. 3.Search for the first occurence where XOR&mask == 1. WDYT?
@shikhar2k013 жыл бұрын
LGTM
@patilsoham5 жыл бұрын
greatest explanation. everything looks simple when you explain it.
@techdose4u5 жыл бұрын
Thanks :)
@ManishKumar-ys5oj4 жыл бұрын
simple aproach: taking xor of both no...and find index of right most setbit of xor.
@techdose4u4 жыл бұрын
Correct.
@aryanjindal1274 жыл бұрын
sir thanks for your simple and different solutions bit masking is really really very helpful
@techdose4u4 жыл бұрын
Yep 😊
@motasim34564 жыл бұрын
We can also do something like, right shifting both the numbers until one of them become even and another one becomes odd.
@saichennu52885 жыл бұрын
Great explanation sir..
@techdose4u5 жыл бұрын
Thanks :)
@AtulDislay5 жыл бұрын
Great explanation as usual 🙌
@techdose4u5 жыл бұрын
Thanks :)
@saichennu52885 жыл бұрын
Sir, upload some dsa concepts like greedy, dynamic programming,brute force etc.
@techdose4u5 жыл бұрын
Bro currently I am doing some videos on graph because many of you had requested it. I will be going home for Christmas and New year. So I will make some videos on hash and heap. After I come back I will surely continue DP and start with greedy. This limitation is due to time. I hope you understand :)
@abhaytiwari64115 жыл бұрын
bro I only understand bruteforce method thanks for explaning in easy way
@techdose4u5 жыл бұрын
You dint understand the bitmasking method?
@abhaytiwari64115 жыл бұрын
Ya because it is complicated
@HomemadeTechARC085 жыл бұрын
Sir, the efficient approch is taking the same no of operations as bruteforce.
@HomemadeTechARC085 жыл бұрын
Still we are going to compare the N bits in the binary representation
@techdose4u5 жыл бұрын
@@HomemadeTechARC08 Actually in the bruteforce, you need to find the binary representation but in efficient approach, we are solving using decimal numbers without converting it to binary :) So, time is very less as compared to bruteforce.
@shubhiagarwal40474 жыл бұрын
sir isme koi bhi glti nhi h but output is not coming by ur approach #include using namespace std; int main() { int t;cin>>t; while(t--) { int m,n;cin>>m>>n; int count,mask=1; while((mask&m)==(mask&n)) { mask
@techdose4u4 жыл бұрын
For which test case is the answer coming wrong?
@shubhiagarwal40474 жыл бұрын
@@techdose4u 387 885 iske liye...
@shubhiagarwal40474 жыл бұрын
@@techdose4u sir really u replied. I m glad and relieved
@ayushgarg59295 жыл бұрын
the better solution will be firstly take xor of both the numbers then find out the position of first set bit in the resultant ...that will be our answer
@priyankapardesiramachander8713 жыл бұрын
sir, can't we just XOR a and b.. then perform 'Find rightmost set bit' method?
@techdose4u3 жыл бұрын
Yes
@AshutoshJha-k1l Жыл бұрын
Instead of this approach we can use the xor approach, by applying the concept that (0^1) or (1^0)=1
@rjagan69513 жыл бұрын
Corner case , what if both values are same??
@susovanghosh60504 жыл бұрын
I think it can even be done like this as well : answer=a xor b and then check the rightmost set bit of answer.
@muktiranjanmohapatra97855 жыл бұрын
🙏 Teacher
@techdose4u5 жыл бұрын
:D
@bhupeshpattanaik71504 жыл бұрын
one more way , easier int firstSetBit(int n) // gives first position where 1 is found { int i=0; while(n) { i++; if(n&1) return i; n = n>>1; } } int posOfRightMostDiffBit(int m, int n) { if(m==n) return -1; int t = m^n; // finding XOR of both number return firstSetBit(t); }
@jaydeepmahajan65984 жыл бұрын
You can also find this taking square root of x & (-x) +1
@b.sainathreddy45674 жыл бұрын
#include using namespace std; //method 1 int main() { // taking the xor of two numbers and finding the right most significant bit // will give the right most different bit int a = 10, b = 14; int c = a ^ b; int rsbm = c & -c; int counter = 1; cout
@abhilashpatel30364 жыл бұрын
Didn't watch till end. But the efficient approach will be using XOR. His approach is too slow.
@rajpalsinghgamer95 Жыл бұрын
No no😂🤣🤬👿🤪you are a kid🤘
@jpakash19994 жыл бұрын
sir please solve the question i sent you through facebook
@techdose4u4 жыл бұрын
I think you sent codechef course. If I get time I will try to explain. I am busy this month.
@jpakash19994 жыл бұрын
Sure thank you anyways
@jpakash19994 жыл бұрын
That was a question asked in zoho interview sir ,don't know it's actual source