Find rightmost different bit between 2 numbers

  Рет қаралды 6,981

Techdose

Techdose

Күн бұрын

Пікірлер: 42
@uditagrawal6603
@uditagrawal6603 3 жыл бұрын
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?
@shikhar2k01
@shikhar2k01 3 жыл бұрын
LGTM
@patilsoham
@patilsoham 5 жыл бұрын
greatest explanation. everything looks simple when you explain it.
@techdose4u
@techdose4u 5 жыл бұрын
Thanks :)
@ManishKumar-ys5oj
@ManishKumar-ys5oj 4 жыл бұрын
simple aproach: taking xor of both no...and find index of right most setbit of xor.
@techdose4u
@techdose4u 4 жыл бұрын
Correct.
@aryanjindal127
@aryanjindal127 4 жыл бұрын
sir thanks for your simple and different solutions bit masking is really really very helpful
@techdose4u
@techdose4u 4 жыл бұрын
Yep 😊
@motasim3456
@motasim3456 4 жыл бұрын
We can also do something like, right shifting both the numbers until one of them become even and another one becomes odd.
@saichennu5288
@saichennu5288 5 жыл бұрын
Great explanation sir..
@techdose4u
@techdose4u 5 жыл бұрын
Thanks :)
@AtulDislay
@AtulDislay 5 жыл бұрын
Great explanation as usual 🙌
@techdose4u
@techdose4u 5 жыл бұрын
Thanks :)
@saichennu5288
@saichennu5288 5 жыл бұрын
Sir, upload some dsa concepts like greedy, dynamic programming,brute force etc.
@techdose4u
@techdose4u 5 жыл бұрын
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 :)
@abhaytiwari6411
@abhaytiwari6411 5 жыл бұрын
bro I only understand bruteforce method thanks for explaning in easy way
@techdose4u
@techdose4u 5 жыл бұрын
You dint understand the bitmasking method?
@abhaytiwari6411
@abhaytiwari6411 5 жыл бұрын
Ya because it is complicated
@HomemadeTechARC08
@HomemadeTechARC08 5 жыл бұрын
Sir, the efficient approch is taking the same no of operations as bruteforce.
@HomemadeTechARC08
@HomemadeTechARC08 5 жыл бұрын
Still we are going to compare the N bits in the binary representation
@techdose4u
@techdose4u 5 жыл бұрын
@@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.
@shubhiagarwal4047
@shubhiagarwal4047 4 жыл бұрын
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
@techdose4u
@techdose4u 4 жыл бұрын
For which test case is the answer coming wrong?
@shubhiagarwal4047
@shubhiagarwal4047 4 жыл бұрын
@@techdose4u 387 885 iske liye...
@shubhiagarwal4047
@shubhiagarwal4047 4 жыл бұрын
@@techdose4u sir really u replied. I m glad and relieved
@ayushgarg5929
@ayushgarg5929 5 жыл бұрын
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
@priyankapardesiramachander871
@priyankapardesiramachander871 3 жыл бұрын
sir, can't we just XOR a and b.. then perform 'Find rightmost set bit' method?
@techdose4u
@techdose4u 3 жыл бұрын
Yes
@AshutoshJha-k1l
@AshutoshJha-k1l Жыл бұрын
Instead of this approach we can use the xor approach, by applying the concept that (0^1) or (1^0)=1
@rjagan6951
@rjagan6951 3 жыл бұрын
Corner case , what if both values are same??
@susovanghosh6050
@susovanghosh6050 4 жыл бұрын
I think it can even be done like this as well : answer=a xor b and then check the rightmost set bit of answer.
@muktiranjanmohapatra9785
@muktiranjanmohapatra9785 5 жыл бұрын
🙏 Teacher
@techdose4u
@techdose4u 5 жыл бұрын
:D
@bhupeshpattanaik7150
@bhupeshpattanaik7150 4 жыл бұрын
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); }
@jaydeepmahajan6598
@jaydeepmahajan6598 4 жыл бұрын
You can also find this taking square root of x & (-x) +1
@b.sainathreddy4567
@b.sainathreddy4567 4 жыл бұрын
#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
@abhilashpatel3036
@abhilashpatel3036 4 жыл бұрын
Didn't watch till end. But the efficient approach will be using XOR. His approach is too slow.
@rajpalsinghgamer95
@rajpalsinghgamer95 Жыл бұрын
No no😂🤣🤬👿🤪you are a kid🤘
@jpakash1999
@jpakash1999 4 жыл бұрын
sir please solve the question i sent you through facebook
@techdose4u
@techdose4u 4 жыл бұрын
I think you sent codechef course. If I get time I will try to explain. I am busy this month.
@jpakash1999
@jpakash1999 4 жыл бұрын
Sure thank you anyways
@jpakash1999
@jpakash1999 4 жыл бұрын
That was a question asked in zoho interview sir ,don't know it's actual source
Find First Set Bit In Integer Number
6:29
CppNuts
Рет қаралды 6 М.
Find missing and repeating number
9:55
Techdose
Рет қаралды 47 М.
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Find rightmost set bit efficiently
7:30
Techdose
Рет қаралды 25 М.
Bit Manipulation Series Part 5  ||Reverse Bits
6:14
Code with Alisha
Рет қаралды 20 М.
How a Russian student invented a faster multiplication method
18:48
How to Remember Everything You Read
26:12
Justin Sung
Рет қаралды 3,4 МЛН
AVL Trees & Rotations (Self-Balancing Binary Search Trees)
20:38
Back To Back SWE
Рет қаралды 366 М.
Rotate bits of a number | GeeksforGeeks
5:11
GeeksforGeeks
Рет қаралды 58 М.
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН