L2. Must Know Tricks in Bit Manipulation | Swap two numbers without third variable

  Рет қаралды 67,586

take U forward

take U forward

3 ай бұрын

Notes/Codes/Problem links under day 8 of A2Z DSA Course: takeuforward.org/strivers-a2z...
Follow us on our other social media handles: linktr.ee/takeuforward

Пікірлер: 96
@Noob_Coder1234
@Noob_Coder1234 3 ай бұрын
REMEMBER IF STRIVER IS MAKING , THEN IT WILL BE THE BEST PLAYLIST ON BIT MANIPULATION
@modiji8706
@modiji8706 3 ай бұрын
1. Swap two numbers - 00:00 2. Check if ith bit is set or not - 3:47 3. set ith Bit - 10:47 4. clear ith Bit - 14:27 5. Toggle ith Bit - 17:52 6.Remove the last set Bit - 21:23 7. Check if a number is power of 2 or not - 28:26 8.count the number of set bits - 31:24
@NAMAN-wj7dj
@NAMAN-wj7dj 2 ай бұрын
thanku modi ji ! abki baar 400 paar 👍
@modiji8706
@modiji8706 2 ай бұрын
@@NAMAN-wj7dj Vote dena mt bhulna Abki baar Modi Sarkar
@02deepak
@02deepak 2 ай бұрын
@@modiji8706 modi ji wo recession ka kuch hojata toh badhiya maan lgta voting m
@himanshutiwari6614
@himanshutiwari6614 2 ай бұрын
​@@02deepakmodiji khud pdh rhe hai dsa😅
@modiji8706
@modiji8706 2 ай бұрын
RastraPati Bhawan ma A jao kl ispe wartalap krte hai
@SuvradipDasPhotographyOfficial
@SuvradipDasPhotographyOfficial 23 сағат бұрын
Awesome Striver, done with sliding window and two pointers and now started with bit manipulation yesterday
@user-tk3td3nc4q
@user-tk3td3nc4q 3 ай бұрын
Never seen better teacher than u
@Benstokes555
@Benstokes555 3 ай бұрын
YESS
@nguyengiahuy6292
@nguyengiahuy6292 3 ай бұрын
struggling so much with this topic alone. Thank you for the series!!!!
@knowthrvdo
@knowthrvdo 3 ай бұрын
Thanks for starting uploading again it is very helpful for us.
@bhushandharne8827
@bhushandharne8827 3 ай бұрын
Sir, Your Techniques are superb
@tamannaverma4178
@tamannaverma4178 3 ай бұрын
Thanks for all these efforts :)
@leaguesonu9354
@leaguesonu9354 3 ай бұрын
hats off man for your hardwork
@kbsce
@kbsce Ай бұрын
Neatly, clearly explained which anyone can easily understand 😊really appreciated your efforts😊
@coderspathway
@coderspathway Ай бұрын
I have paid DSA course from GFG. But not able to understand BIT manipulation. After watching this playlist by striver I feel the striver did it better than any other paid course in the market.
@yashwanthbm7543
@yashwanthbm7543 24 күн бұрын
same here i paid for my gfg self paced but i'm now watching strivers youtube to solve DSA
@AdityaSharma-er3gs
@AdityaSharma-er3gs 7 сағат бұрын
33:00 here you can simply do this public static int countSetBit(int num){ int count = 0; int one = 1; while(num > 0){ if((num & one) == 1){ count++; } num = num >> 1; } return count; }
@rahuljain224
@rahuljain224 2 ай бұрын
Salute to your hardwork and explanation
@KaushalDhruw
@KaushalDhruw 2 ай бұрын
before this I thought I knew bitwise operations. But the tricks you've shown are awesome. Thanks again.
@tgayush1424
@tgayush1424 7 күн бұрын
amazing video covering all concepts, soon will be mastering bit manipulations by completing your playlist.Before i used to be scared of seeing bits but now it's easy , even i started to use , today i used in one question and solved that question easily.
@Benstokes555
@Benstokes555 3 ай бұрын
MY MAN IS BACKKKKKKKKKK
@stith_pragya
@stith_pragya 2 ай бұрын
Understood....Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@lakshmanlk977
@lakshmanlk977 2 ай бұрын
Ohh striver such an amazing lecture ..
@veerverma5586
@veerverma5586 3 ай бұрын
Keep going 🏆
@user-nb6fx1rf9i
@user-nb6fx1rf9i 3 ай бұрын
Many times I thought to comment on his post and lastly just leaving it by pressing like button.. thinking that kya kya bolega log,,! Is there anyone else like me ? Aisa koi h Banda Jo striver se bhi accha padhata ho ! I don't think so some one exist ❤
@pranavmittal9619
@pranavmittal9619 3 ай бұрын
ek h lekin me nahi batunga bas hint de deta hu : 2 crore ka package chod diya bande ne
@user-nb6fx1rf9i
@user-nb6fx1rf9i 3 ай бұрын
​@@pranavmittal9619Bhai hai to bata do jara hum bhi Jane kon h, teacher hi na , terrorist thode h Jo bata na paoge 😂 kahi tum hi to nahi ho wo 2 cr vala Banda Jo chhup chup ke bit manipulation ka maja le rahe ho😊
@Quantumcorekick
@Quantumcorekick Ай бұрын
i dont know how to say thank you but you saved me striver . thank you>3000
@user-qb8vy2gy2w
@user-qb8vy2gy2w 3 ай бұрын
Thanks for teaching every possibility answer for the problems❤❤❤
@tapasyadimree9651
@tapasyadimree9651 Ай бұрын
17:20 when finding ~(1
@GoluKumar-sb2si
@GoluKumar-sb2si Ай бұрын
same doubt bro
@AkOp-bf9vm
@AkOp-bf9vm 28 күн бұрын
i think we cannot access 2's complement part and can only access negated part of the number maybe i am not sure
@ishwarreddy8820
@ishwarreddy8820 3 ай бұрын
If striver is making then it will be the best playlist ;
@sakshikatiyar5353
@sakshikatiyar5353 3 ай бұрын
u are the best teacher
@anshrathore2731
@anshrathore2731 3 ай бұрын
Thank you so much BHAIYA 🙏🙏🙏
@SumitKumar-qg4ps
@SumitKumar-qg4ps 3 ай бұрын
to clear ith bit(0 indexed), we can just do N = n xor (1
@chickukoshti3741
@chickukoshti3741 3 ай бұрын
toggle
@AnushkaMishra8
@AnushkaMishra8 3 ай бұрын
Yes , but it will work same as toggling if the bit is not set and we don't want that , if the bit will be 0 then also it will be changed to 1 if we do this.
@HaamroNotes
@HaamroNotes Ай бұрын
@@AnushkaMishra8 yeah bro
@riachoudhary__
@riachoudhary__ 3 ай бұрын
Thank you for making this video
@user-vf5gi2fd8y
@user-vf5gi2fd8y 2 ай бұрын
super amazing!!
@thaman701
@thaman701 3 ай бұрын
Great sir.❤
@banothutharun2743
@banothutharun2743 Ай бұрын
simple superb sir
@user-or5oz1pk2x
@user-or5oz1pk2x Ай бұрын
Thanks a lot Bhaiya
@UECAshutoshKumar
@UECAshutoshKumar 3 ай бұрын
Thank you sir 🙏
@vijeshsshetty
@vijeshsshetty 3 ай бұрын
thank you sir ji
@KapilSharma56419
@KapilSharma56419 8 күн бұрын
there is a question on GFG : Count total set bits You are given a number N. Find the total count of set bits for all numbers from 1 to N(both inclusive). which shows TLE by all your methods can you please explain it .
@subee128
@subee128 3 ай бұрын
Thank you very much
@ryugagaming195
@ryugagaming195 3 ай бұрын
Sir plz make more videos on sliding window
@uditgarg6508
@uditgarg6508 8 күн бұрын
for checking ith bit set just do right shift by ith and check the resukting num is odd. if it is , it is set. else , not ...
@ok-jg9jb
@ok-jg9jb 2 ай бұрын
Thanks❤
@ReNaq313
@ReNaq313 2 ай бұрын
39:00 -> repeatedly removing the rightmost set bits and taking the count of times we did this operation would give us the number of set bits in a number
@roshankumar280
@roshankumar280 21 күн бұрын
One-Liner: 1) Swapping Two Numbers : Num1=(Num1^Num2); Num2=(Num1^Num2); Num1=(Num1^Num2); 2) Check If i’th bit is set or not: if((Num&(1
@Neo-mx2yf
@Neo-mx2yf Күн бұрын
So in prev video, a method was taught to find ~x but it is a bit unclear. Let me try clear it up. Actually, ~x is just 1's complement of x, i.e., flip all bits. Eg: ~19 = ~(010011) = (101100) in binary = -20 in decimal Now we know (-x) is actually 2's complement of x. So what he taught is actually to find -x manually. Take prev eg, ~(010011) = (101100) in binary = -(2's complement of 101100) in decimal = -(010100) in decimal = -20 Take other way, ~(-20) = ~(101100)=010011 in binary=(directly) 19 Note: For easiness just assume that instead of 32 bits, there are only 6 bits here.
@chaitrabhat8199
@chaitrabhat8199 Ай бұрын
Understood
@ajayprabhu465
@ajayprabhu465 Ай бұрын
Helpfull
@parvahuja7618
@parvahuja7618 3 ай бұрын
thanks
@navinchaudhary2812
@navinchaudhary2812 3 ай бұрын
understood
@saikrishna872
@saikrishna872 3 ай бұрын
First one to see❤
@hakunamatata-nl4js
@hakunamatata-nl4js 17 күн бұрын
Gawd level
@sristikabora526
@sristikabora526 29 күн бұрын
I got it :)
@rahulnagwanshi2348
@rahulnagwanshi2348 Ай бұрын
check if a number is a power of two -> !(N & 1)
@sachinvarma9949
@sachinvarma9949 Ай бұрын
Bro loves 13 anyways best lecture on yt.
@nashalafroz
@nashalafroz 3 ай бұрын
17:30 sir if we use not operator wouldnt the number converted into its 2's complement
@janarddansarkar2694
@janarddansarkar2694 3 ай бұрын
same doubt. Someone please clearify
@janarddansarkar2694
@janarddansarkar2694 3 ай бұрын
What I am assuming is since we are not storing the negative answer, so 2's complement is not used. If the answer was negative, then to store it, 2's complement would have been used. This is my assumption though. Not sure
@human0225
@human0225 3 ай бұрын
Any solution to this I am still struggling with this.
@kumarnishantnitallahabad160
@kumarnishantnitallahabad160 2 ай бұрын
same doubt
@akshatchoudhary2783
@akshatchoudhary2783 Ай бұрын
Bhaiya in the Clear bit Soluton can we use XOR operation? like below n = 13, i =2 13 -> 1101 1
@iamnoob7593
@iamnoob7593 Ай бұрын
SUPERR
@kingraj4797
@kingraj4797 2 ай бұрын
I think right and left shift operation or not required for finding the i th bit is set(1) or reset(0) for given binary digits Here I have code please verify it it is taking O(1) time complexity to find it.. // ith bit is set or reset import java.util.*; class SetOrReset{ public static void main(String args[]) { Scanner sc=new Scanner(System.in); String str=sc.next(); int i=1; int j=str.length()-1; int x=str.charAt(j-i)-'0'; if(x==1){ System.out.println("Set"); }else{ System.out.println("Reset"); } } }
@anupkhismatrao9280
@anupkhismatrao9280 18 күн бұрын
@AmandeepSingh-rd6ql
@AmandeepSingh-rd6ql 2 ай бұрын
Any reason for using left or right shift operator what is the intuition behind it anyone
@ifirdaus0_0
@ifirdaus0_0 3 ай бұрын
can i use (n ^ (1
@aayushgupta7839
@aayushgupta7839 3 ай бұрын
yes you can , I have also done the same for the code ninja question and it cleared all the test cases.
@coder_07
@coder_07 2 ай бұрын
Yes , but it will work same as toggling if the bit is not set and we don't want that , if the bit will be 0 then also it will be changed to 1 if we do this.
@sagarray707
@sagarray707 3 ай бұрын
Mai first
@saqibaqeel9196
@saqibaqeel9196 3 ай бұрын
Is this question available in leet code
@user-lx3hb7dt2w
@user-lx3hb7dt2w 3 ай бұрын
when we need to count the total set bits from 1 to N , the following code gives TLE when N=10^9 because of the for loop. how can this be optimised ? int count(int n) { int cnt=0; while(n!=0) { if(n&1==1) cnt++; n=n>>1; } // if(n==1) cnt++; return cnt; } int countSetBits(int n) { //Write your code here int ans=0; if(n==1) return 1; for(int i=1;i
@RaviKumar-sn6tu
@RaviKumar-sn6tu Ай бұрын
bhaiya please string start kro !!!!!!!!!!!!!!!!!!!!!
@jarvis3551
@jarvis3551 3 ай бұрын
can anyone please add timestamps for all questions solved?
@raveenakumari6724
@raveenakumari6724 Ай бұрын
0 xor 0 is 1 bhaiya.. if we use xor in toggle then it might give us the wrong answer
@nova9157
@nova9157 Ай бұрын
0 xor 0 is not 1
@nova9157
@nova9157 Ай бұрын
its 0
@latoyapope5384
@latoyapope5384 Ай бұрын
"Promo SM"
@CodewithAnuragBassu
@CodewithAnuragBassu 3 ай бұрын
Thanku so much bhaiya❤❤🙏🙏🙏🙏
@user-tk2vg5jt3l
@user-tk2vg5jt3l 2 ай бұрын
Thank you Bhaiya
@chiragbansod8252
@chiragbansod8252 3 ай бұрын
understood
@hardikpatel352
@hardikpatel352 17 күн бұрын
understood
@shaiksoofi3741
@shaiksoofi3741 10 күн бұрын
understood
L3. Minimum Bit Flips to Convert Number | Bit Manipulation
7:00
take U forward
Рет қаралды 26 М.
L6. Single Number II | Bit Manipulation
31:19
take U forward
Рет қаралды 25 М.
터키아이스크림🇹🇷🍦Turkish ice cream #funny #shorts
00:26
Byungari 병아리언니
Рет қаралды 27 МЛН
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 170 #shorts
00:27
Children deceived dad #comedy
00:19
yuzvikii_family
Рет қаралды 6 МЛН
Получилось у Вики?😂 #хабибка
00:14
ХАБИБ
Рет қаралды 6 МЛН
10 Math Concepts for Programmers
9:32
Fireship
Рет қаралды 1,8 МЛН
I Played Fabiano Caruana
12:03
Anna Cramling
Рет қаралды 213 М.
Coding Interviews Be Like
5:31
Nicholas T.
Рет қаралды 6 МЛН
❌ Don't Run Behind 500 LEETCODE Problems ❌ Focus on QPCD
8:31
L7. Single Number III | Bit Manipulation
24:03
take U forward
Рет қаралды 26 М.
L4. Power Set | Bit Manipulation
12:38
take U forward
Рет қаралды 27 М.
터키아이스크림🇹🇷🍦Turkish ice cream #funny #shorts
00:26
Byungari 병아리언니
Рет қаралды 27 МЛН