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
Bro there is competative programming sheet also, if you have finished that do a deep dive in stl if c++ or collections if in Java, then do math a lot, remember no tutorial can prep you for competitive programming it is just you and you have to go deep dive in it and eventually you will learn ,from some who is 2000 on Codeforces. Best of luck
@@adarshrai1390 bro how you counter questions from the topic that you didn't covered, does that mean you have to first cover all the dsa topics and then start cp, btw congo bro, i respect your rating!!
For those who not understand bucket concept , forget about bits and try with numbers only to understand concept . we want to check (ones == twos)but we don't want to lose value of ones there for using ( & ~ twos )
at 26:35 i feel you wrote and spoke correctly but earlier in rules you stated point number two as it will go to twos, if it is in ones! please confirm striver.
both are correct because that line is used to execute the point "num[i] will go to twos if it is in ones" . lets consider the the array be arr={2,2,2,3} step 1: ones=2 and twos=0 step 2: num[i]==2 and ones is also 2 which means we have to delete 2 from ones. now ones==0 if it the first occurrence of 2 then it should be present in ones but it is not (because ones==0) which means it is the second occurrence of 2 which means 2 is now added in twos that why we use the condition that ***it should not be present in ones*** by ~ones.
i have one question like i was doing dry and run on array [5,5,5,6,4,4,4] after when array element first 4 comes if we take xor with what ones contains so it technically has 6 bcoz it occured ones then when we xor 6^4 it will not remain 6 pls tell me what im doing wrong something is off i cant pinpoint pls help guys!!
Can any one please tell When I am doing dry run on [1,2,3,2,3,2,3] It is giving random ans and not the desired output then how at hardware level this is giving correct answer the method was nice but why it didn't prove it's correctness in dry run ????
it will give desired output after the complete traversal of array may be you done some error in your calculation #include using namespace std; int main() { vector arr={1,2,3,2,3,2,3}; int ones=0,twos=0; int n=arr.size(); for(int i=0;i
pls tell me why in system im getting correct result even if the array is unsorted but while im doing dry and run why im just getting some random result which i dont want pls help me unveil tell me the bit manipulation trick which maybe im not able to see through my naked eyes im not able to pinpoint the mistake pls help guys!!
at 17:20 if we take this example after sorting [ 1,1,1,2,3,3,3,4,4,4] then according to code it will give 2 and 3 as a ans ,, but ans should be only 2 so how this code is true .Can anyone explain?
it will give desired output after the complete traversal of array may be you done some error in your calculation. #include using namespace std; int main() {
vector arr={1,2,3,2,3,2,3}; int ones=0,twos=0; int n=arr.size(); for(int i=0;i
Sir i guess at 10:45 , you have used 2 for loops , first goes from i to 31 and second goes from j to n , which is i guess wrong because according to this we are counting the bits row wise but we have to count it colum wise so our loop should be like i to n and j to 31, correct me if im wrong
no, the way in the video is correct. we want to count the number of 1's in each bit position. so we need to iterate through each bit position first, and then each number from the array to count how many 1's there are. hopefully that makes sense
mind blowing explanation, i love how in depth you are teaching the concepts.
amazing explanation, it took me some time to grasp the concepts of buckets but finally I understood every step. 😅😅
Excellent explanation. Really loved the Bucket method
Wonderful explanation man. Keep up the good work.
Thank you bhaiya.
i never imagine that a question can have that many solutions😂😂
The bucket concept was❤
Thank you bhaiya
Make playlist or videos for Competitive programming because I have completed your dsa series 😊
how much time did it took to complete the playlist and how many videos were you watching everyday
Bro there is competative programming sheet also, if you have finished that do a deep dive in stl if c++ or collections if in Java, then do math a lot, remember no tutorial can prep you for competitive programming it is just you and you have to go deep dive in it and eventually you will learn ,from some who is 2000 on Codeforces. Best of luck
Mastering Segment tree, BIT,dp and graph will surely put you cm or master level but surely it's gonna take a lot of time and effort.
@@adarshrai1390 bro how you counter questions from the topic that you didn't covered, does that mean you have to first cover all the dsa topics and then start cp,
btw congo bro, i respect your rating!!
What about string , from where it should be learnt
kyaaa pyaar solution tha bucket wala loving ittttt
WILL THE BUCKET WORK IF THE NO,S ARE NOT IN CLUSTERS
@@ArkojyotiDeyOfficial Yes, Works for every possible arrangment of the elements.
Thank you sir 😁
Thank sir 🤩🤩
Please Update A2Z DSA Course/Sheet for this series, it helps a lot in revision
class Solution {
public:
int singleNumber(vector& nums) {
int ans = 0;
for(int bitIndex = 0; bitIndex
Bucket Method😍
understood
❣
🔥🔥🔥
ohh, i love naive solutions
yehi too chahiye tha
For those who not understand bucket concept , forget about bits and try with numbers only to understand concept .
we want to check (ones == twos)but we don't want to lose value of ones there for using ( & ~ twos )
i didnt understand this concept can you explain
For 2nd Bucket - will go to twos if it is in ones
- I think there will be a correction here
that - it will go to twos if not in ones
Same Thought Bro
public int singleNumber (int[]nums){
int ones=0,twos=0;
for(int num:nums){
ones=ones^(num&~twos);
twos=twos^(num&~ones);
}
return ones;
}
at 26:35 i feel you wrote and spoke correctly but earlier in rules you stated point number two as it will go to twos, if it is in ones! please confirm striver.
both are correct because that line is used to execute the point "num[i] will go to twos if it is in ones" .
lets consider the the array be arr={2,2,2,3}
step 1: ones=2 and twos=0
step 2: num[i]==2 and ones is also 2 which means we have to delete 2 from ones.
now ones==0
if it the first occurrence of 2 then it should be present in ones but it is not (because ones==0) which means it is the second occurrence of 2 which means 2 is now added in twos that why we use the condition that ***it should not be present in ones*** by ~ones.
First one to comment! Excited ❤
Congratulations bro🎉🎉🎉
kl rashtrapati bhavan aa jana prize lene
@@modiji8706 😂😂😂😂😂😂
at 7:54 he is more serious then my carrer
that's why u are here
UNABLE TO UNDERSTAND BUCKET METHOD !
Same vro😢
i have one question like i was doing dry and run on array [5,5,5,6,4,4,4] after when array element first 4 comes if we take xor with what ones contains so it technically has 6 bcoz it occured ones then when we xor 6^4 it will not remain 6 pls tell me what im doing wrong something is off i cant pinpoint pls help guys!!
this is not wrong the answer will be (6^4)&(~two). ones will change here but if you completely traverse whole array the ones will contain 6
Nice explanation. However I am not able to understand the bucket method yet...Does it work only for the sorted array?
Ya similar doubt, I think the array should be sorted....
No it works for unsorted array as well
Can any one please tell When I am doing dry run on [1,2,3,2,3,2,3] It is giving random ans and not the desired output then how at hardware level this is giving correct answer the method was nice but why it didn't prove it's correctness in dry run ????
it will give desired output after the complete traversal of array may be you done some error in your calculation
#include
using namespace std;
int main()
{
vector arr={1,2,3,2,3,2,3};
int ones=0,twos=0;
int n=arr.size();
for(int i=0;i
can this solution of checking bits work in case of negative numbers as well?
yes
17:39 that range is wrong. equalto is missing
I sometimes wonder why he is in not from IITs, he should have a permanent seat there
The question and notes links are not available in the dsa sheet. Please update it!!
bro i am also searching for it 🤣🤣
i have gone through the dsa sheet but unable to find the notes, can anyone guide me where the notes exactly is
not update yest..
Can it be explained in easy way ? plz
Why can't we xor each element to get the element which is occuring once?
as elements are not in even number if we xor 1 1 1 2 then 1^2 will be left at the end
@@artifice_abhi ok ok got it... thank you for the explanation
pls tell me why in system im getting correct result even if the array is unsorted but while im doing dry and run why im just getting some random result which i dont want pls help me unveil tell me the bit manipulation trick which maybe im not able to see through my naked eyes im not able to pinpoint the mistake pls help guys!!
i think we add the number and also delete it if it is duplicate thats why only unique element will remain in ones
at 17:20 if we take this example after sorting [ 1,1,1,2,3,3,3,4,4,4] then according to code it will give 2 and 3 as a ans ,, but ans should be only 2 so how this code is true .Can anyone explain?
loop will not go ahead after finding 2....2 will be returned
no it only return ans==2 for every index we are checking we will use
if(arr[i] != arr[i-1]) return arr[n-1];
it will return n-1 index value
kuch samja nahi
pls help me im not getting answer while im doing dry nd run
it will give desired output after the complete traversal of array may be you done some error in your calculation.
#include
using namespace std;
int main()
{
vector arr={1,2,3,2,3,2,3};
int ones=0,twos=0;
int n=arr.size();
for(int i=0;i
suggestion for you:: you can also try to get answer from chatgpt . most of the time it will find error in your code . It will save your lot of time.
Sir i guess at 10:45 , you have used 2 for loops , first goes from i to 31 and second goes from j to n , which is i guess wrong because according to this we are counting the bits row wise but we have to count it colum wise so our loop should be like i to n and j to 31, correct me if im wrong
no, the way in the video is correct. we want to count the number of 1's in each bit position. so we need to iterate through each bit position first, and then each number from the array to count how many 1's there are. hopefully that makes sense
bhai yr aisi english mt bolo ki smgh hi na aye kuch chota sa concept smjhne me itni mehnt lg gyi
😂😂 ha bhai sach m kabhi kabhi samjh m aana band ho jata h ,,bhai ki english to nxt lvl hai
#include
using namespace std;
int singleNumII(vector a,int n)
{
int ones=0,twos=0;
int i;
for(i=0;i
U need to take all elements thrice except one element. If u change 6 to 4.. you'll get the correct output.