Notes/Codes/Problem links under day 8 of A2Z DSA Course: takeuforward.o... Follow us on our other social media handles: linktr.ee/take...
Пікірлер: 190
@modiji870610 ай бұрын
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-wj7dj10 ай бұрын
thanku modi ji ! abki baar 400 paar 👍
@modiji870610 ай бұрын
@@NAMAN-wj7dj Vote dena mt bhulna Abki baar Modi Sarkar
@02deepak9 ай бұрын
@@modiji8706 modi ji wo recession ka kuch hojata toh badhiya maan lgta voting m
@himanshutiwari66149 ай бұрын
@@02deepakmodiji khud pdh rhe hai dsa😅
@modiji87069 ай бұрын
RastraPati Bhawan ma A jao kl ispe wartalap krte hai
@Noob_Coder123410 ай бұрын
REMEMBER IF STRIVER IS MAKING , THEN IT WILL BE THE BEST PLAYLIST ON BIT MANIPULATION
@siddiqabr71103 ай бұрын
Have you ever watched kunal kushwaha's videos
@aayambhatt53633 ай бұрын
@@siddiqabr7110 his videos arent any good
@mayankagarwal67752 ай бұрын
@@aayambhatt5363 yes !! I had started my dsa journey from kunal but now shifted to striver after understanding basics of dsa.
@lillyput2275Ай бұрын
@@aayambhatt5363I don’t understand his way of teaching
@CDK-TechАй бұрын
@@aayambhatt5363 His videos was once good , now it's not 😭
@fazfavas-d6j10 ай бұрын
Never seen better teacher than u
@Benstokes55510 ай бұрын
YESS
@raorao73296 ай бұрын
true
@roshankumar2807 ай бұрын
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
@Monjaverse4 ай бұрын
Love you bro ❤❤❤
@nguyengiahuy629210 ай бұрын
struggling so much with this topic alone. Thank you for the series!!!!
@uzzal.cse424 ай бұрын
Crystal clear explanation. Highly recommended for those who does not know anything about bit manipulation.
@SumitKumar-qg4ps10 ай бұрын
to clear ith bit(0 indexed), we can just do N = n xor (1
@chickukoshti374110 ай бұрын
toggle
@AnushkaMishra810 ай бұрын
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.
@HaamroNotes8 ай бұрын
@@AnushkaMishra8 yeah bro
@SuvradipDasPhotographyOfficial7 ай бұрын
Awesome Striver, done with sliding window and two pointers and now started with bit manipulation yesterday
@AdityaSharma-er3gs7 ай бұрын
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; }
@priyanshugupta7840Ай бұрын
it is almost the same thing taking the same time except you create one more variable num ;)
@udayshankar-e6v10 ай бұрын
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 ❤
@pranavmittal961910 ай бұрын
ek h lekin me nahi batunga bas hint de deta hu : 2 crore ka package chod diya bande ne
@udayshankar-e6v10 ай бұрын
@@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😊
@raorao73296 ай бұрын
@@pranavmittal9619 who??
@pranavmittal96196 ай бұрын
@@raorao7329 bhai coder army wale rohit negi bhaiya hai hindi lanuage ke liye bas striver best hai lekin Full english me concept grasp karne me dikkat bhi aati hai or striver ka code high level ka rehta hai or rohit negi ka low level ka code lekin output same rehta
@tgayush14247 ай бұрын
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.
@codingp1106 ай бұрын
Best Bit Manipulation tutorial ever!!!
@knowthrvdo10 ай бұрын
Thanks for starting uploading again it is very helpful for us.
@bhushandharne882710 ай бұрын
Sir, Your Techniques are superb
@ankushrai315513 күн бұрын
the efforts this guy puts is just amazing
@KaushalDhruw9 ай бұрын
before this I thought I knew bitwise operations. But the tricks you've shown are awesome. Thanks again.
@tamannaverma417810 ай бұрын
Thanks for all these efforts :)
@ce038_divanshsingh37 ай бұрын
i just stuck to your glow in comment section 😂😂 , forgot about the lecture that is running in the background ..
@Karanssharma038 ай бұрын
i dont know how to say thank you but you saved me striver . thank you>3000
@coderspathway8 ай бұрын
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.
@Thinker-3607 ай бұрын
same here i paid for my gfg self paced but i'm now watching strivers youtube to solve DSA
@harshverma96752 күн бұрын
Bhai aapka knowledge toh kamal ka hai bhai.
@kbsce8 ай бұрын
Neatly, clearly explained which anyone can easily understand 😊really appreciated your efforts😊
@rishavjain508712 күн бұрын
This is just too good to be true bro.. Thanks a lot❤
@momentcoder19 күн бұрын
The best teacher for dsa 🔥🔥
@stith_pragya9 ай бұрын
Understood....Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@rahuljain2249 ай бұрын
Salute to your hardwork and explanation
@leaguesonu935410 ай бұрын
hats off man for your hardwork
@TejeshReddyThippakkagari10 ай бұрын
Thanks for teaching every possibility answer for the problems❤❤❤
@SamirKumarRakshit-c4z5 ай бұрын
int count = 0; int num = 7; while(num > 0){ num = (num & (num-1)); ++count; } print(count) We can also do this in order to count the set bit (1)😊
@JIHYELEE-h2m6 ай бұрын
Wow this is essence of bit manipulation!!!!!!!!!! Thank you so much
@lakshmanlk9779 ай бұрын
Ohh striver such an amazing lecture ..
@ishwarreddy882010 ай бұрын
If striver is making then it will be the best playlist ;
@SaswataMaitra3 ай бұрын
17:20 another approach (n&(INT_MAX^(1
@rohan87584 ай бұрын
*java code* Set ith bit from last, conside 0 based indexing (10:47 ): public static void main(String[] args) { int n = 9; int k = 2; int second_desired_num = 1
@veerverma558610 ай бұрын
Keep going 🏆
@akashddeepchitransh45372 ай бұрын
Knowledge Packed Lecture.
@Benstokes55510 ай бұрын
MY MAN IS BACKKKKKKKKKK
@KapilSharma564197 ай бұрын
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 .
@andrewcenteno34626 ай бұрын
This course was insanely good
@itxamanpanwar85567 ай бұрын
🙏🙏TQ bhaiya for such a good explanation is topic ma smj hi ni aa raaha tha ab sb easy lg r ha
@sakshikatiyar535310 ай бұрын
u are the best teacher
@DeepakKumar-nq4td4 ай бұрын
Hila diye bhaiya ji 🎉🎉🎉❤❤
@tapasyadimree96519 ай бұрын
17:20 when finding ~(1
@GoluKumar-sb2si8 ай бұрын
same doubt bro
@AkOp-bf9vm8 ай бұрын
i think we cannot access 2's complement part and can only access negated part of the number maybe i am not sure
@CodeByRobin4 ай бұрын
same doubt bro ,, I raised this on lecture one as well, but bhaiya is not replying....
@padduchennamsetti65164 ай бұрын
understood ,thanks alot
@utkarshtiwari75006 ай бұрын
To clear ith bit we can do :- return ( n ^ (1
@shivanshpatel18986 ай бұрын
no we cant because 0 ^ 1 is 1 so if ith bit is already zero it will change it to 1
@JunaidhFardeen3 ай бұрын
It is for toggle
@anshrathore273110 ай бұрын
Thank you so much BHAIYA 🙏🙏🙏
@ryugagaming19510 ай бұрын
Sir plz make more videos on sliding window
@ShravanKumar-wg9pv2 ай бұрын
W lecture. Thank you very much sir.
@rithish9936 ай бұрын
17:30 instead we can left shift 1 and use xor operators
@UECAshutoshKumar10 ай бұрын
Thank you sir 🙏
@nashalafroz10 ай бұрын
17:30 sir if we use not operator wouldnt the number converted into its 2's complement
@janarddansarkar269410 ай бұрын
same doubt. Someone please clearify
@janarddansarkar269410 ай бұрын
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
@human022510 ай бұрын
Any solution to this I am still struggling with this.
@kumarnishantnitallahabad1609 ай бұрын
same doubt
@CodeByRobin4 ай бұрын
Same doubt .. You got the answer.
@ganeshjaggineni40973 ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@SHINGAVIKAJAL9 ай бұрын
super amazing!!
@Josuke2175 ай бұрын
Great lecture.
@PavanKumar-jz5ow3 ай бұрын
UNDERSTOOD 🎉🎉😁😁😁😁
@riachoudhary__10 ай бұрын
Thank you for making this video
@rahulpatil2472Ай бұрын
for each problem if you write code that will better, but you already created playlist
@MuraliVardhan-s4sАй бұрын
thank you anna🧡
@CodewithAnuragBassu10 ай бұрын
Thanku so much bhaiya❤❤🙏🙏🙏🙏
@DeepakPatel-d5v8 ай бұрын
Thanks a lot Bhaiya
@edsongeorgerebello547Ай бұрын
In the clearing the set bit won't the negation of the left shift 1 make it a 2's complement and the program will add a 1 to it ?
@banothutharun27439 ай бұрын
simple superb sir
@vijeshsshetty10 ай бұрын
thank you sir ji
@karthik-varma-15793 ай бұрын
Set> Or Clear/Remove -> And Toggle -> Xor
@aryansinha18182 ай бұрын
38:00 around, using the last method
@uditgarg65087 ай бұрын
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 ...
@ReNaq3139 ай бұрын
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
@CodeByRobin4 ай бұрын
somewhere in the comments , i read "computer store binary as flipped but while showing us it do 2's complement to show us -ve binary in interger" is this right?
@cleweric6 ай бұрын
in case of power of 2, n & (n-1) == 0 will not work if n = 0, as 0 is not a power of two, we can rather use n & (-n) == n, which mean AND n with its 2's complement it would result n, if its a power of 2
@thaman70110 ай бұрын
Great sir.❤
@gayathripamarthi84514 ай бұрын
That end music !!!
@Sahilkumar-hj4vm6 ай бұрын
at 17:30 striver do the NOT operator and it flipped all the bits making it a negative number then according to full NOT operator it do 2's complement also but striver stopped at flipping can someone explain me why? edited - ok i get it why computer store binary as flipped but while showing us it do 2's complement to show us -ve binary in interger
@Sonu.Singh.283 ай бұрын
If you find the swapping using xor confusing, then instead of xor operation use the addition and subtraction operation, it will do the job. a = 17 b = 27 a = a + b # a becomes 17 + 27 = 44 b = a - b # b becomes (17 + 27) - 27 = 44 - 27 = 17 a = a - b # a becomes (17 + 27) - 17 = 27
@anantmishra51743 күн бұрын
I HAVE ONE QUESTION WHEN WE ARE CHECKING IF I'th BIT IS SET OR NOT WHILE DOING RIGHT SHIFT OF NUMBER (n-1) TIMES. WOULDN'T IT CHANGES THE INPUT NUMBER SUPPLIED.
@Neo-mx2yf7 ай бұрын
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.
@mahaboobpeershaik6585 ай бұрын
Can we get slides notes, @takeUforward bro?
@music-loverFam5 ай бұрын
Understood😊
@LemesaElias4 ай бұрын
In python you can swap without using a 3rd variable like a , b = b , a
@Phantomex9844 ай бұрын
u can do swap without using 3rd var in all languages just use a = 3, b = 7, b+=a, a = b-a, b = b-a, Output : , a = 7, b = 3,
@k.k.harjeeth54226 ай бұрын
unset the right most set bit : n&(n-1) set the right most unset bit : n | (n+1)
@abhinavraj65074 ай бұрын
At 17:20 striver is not taking 2's complement for NOT operator ? Last video he taught that if after flipping the number becomes negative , we take 2's complement , anyone please help ?
@CodeByRobin4 ай бұрын
same doubt. Please let me know, if you got the answer
@Mohd-1233510 күн бұрын
we can swap without using xor ? a = a + b; b = a - b; a = a - b;
@ansariaburehan263Ай бұрын
Love it.
@aayushgakhar35256 ай бұрын
in clearing the ith bit ques shouldnt we take -1 as while finding not of 1 its sign bit also changes in first step and so it becomes -ve and so we have to find its 2s compli
@CodeByRobin4 ай бұрын
same doubt bro,, if you got the answer. Pease reply
@DeadPoolx17124 ай бұрын
UNDERSTOOD;
@Learnprogramming-q7f9 ай бұрын
Thank you Bhaiya
@akshatchoudhary27838 ай бұрын
Bhaiya in the Clear bit Soluton can we use XOR operation? like below n = 13, i =2 13 -> 1101 1
@CodeByRobin4 ай бұрын
use an example where the ith bit is already 0. You will get to know
@kingraj47979 ай бұрын
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"); } } }
@shashankgsharma09016 ай бұрын
Understood!
@sachinvarma99498 ай бұрын
Bro loves 13 anyways best lecture on yt.
@amanasrani64056 ай бұрын
Amazinngggggggggg❤
@yash3009517 күн бұрын
understood!
@ifirdaus0_010 ай бұрын
can i use (n ^ (1
@aayushgupta783910 ай бұрын
yes you can , I have also done the same for the code ninja question and it cleared all the test cases.
@coder_0710 ай бұрын
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.
@chirag712692 ай бұрын
STRIVER 🤩
@ok-jg9jb10 ай бұрын
Thanks❤
@swaroopvengali5 ай бұрын
Python 1 liners- ============= Swapping two numbers: a = a ^ b; b = a ^ b; a = a ^ b Check if i'th bit is set or not: print("SET" if (Num & (1
@mordernmonk1943 ай бұрын
One-Liner: 1) Swapping Two Numbers : Num1=(Num1^Num2); Num2=(Num1^Num2); Num1=(Num1^Num2); 0000101 = num1 ^0001001 = num2 ________ 0001100 xor of num1 and num2 stored in num1 0001001 = num2 ----- 0000101 xor of (num1 and num2) and num2 stored in num2 0001100 ----- 0001001 2) Check If i’th bit is set or not: if (( Num &(1
@TechieClasher8 ай бұрын
Helpfull
@KartikeyTT6 ай бұрын
tysm sir
@kalkeshvyas78972 ай бұрын
great
@rahulnagwanshi23488 ай бұрын
check if a number is a power of two -> !(N & 1)
@riddhithbanerjee3 ай бұрын
In the power of 2 case...what if the number is 0 or INT_MIN then for 0 it will be n&n-1 = 0&-1 means 0...0000 & 1...1111 its coming 0 then it will return true but actually its not power of 2 And in case of INT_MIN n&n-1 the n-1 value is getting overflowed...please solve the doubt anyone.