Please note that this will work for -ve numbers as well. Negative numbers are represented in two's compliment manner. So if nums is {-3, -3, -3, 1, 1, 1, 2} This will also work because in 2's compliment -3 will be represented as - '1111111111111101' And same will happen for other -3 in nuts. So anyways it will work.
this is accurate running code for python to handle negative no class Solution: def singleNumber(self, nums: List[int]) -> int: result = 0 is_neg = 0 for k in range(0, 32): temp = (1
Respected MIK Sir, The way you start explaining from basic (e.g. Left Shift) is so helpful even for beginner. Your video is made for all kind of viewers right from beginner level to advance level viewer. This helps beginner to progress to advance level. Thank you so much for making our life easier 🙏🏼
class Solution { public: int singleNumber(vector& nums) { unordered_map map; for (int i = 0; i < nums.size(); i++){ map[nums[i]]++; } int ans=0; for (auto x : map){ if(x.second==1) ans=x.first; } return ans; } };
Very clever of them to repeat it thrice instead of twice (cuz u know... If they had given twice, u could just xor the entire array to get that unique number)
It was a different solution than other standard solutions but it was brilliantly explained. It doesn't use any complex logic but it's a slow solution because of the time complexity of O(32*n) and beats only 25% of people. In my opinion, it's still better to use a slow simple solution rather than cramming a difficult solution so Hats off. More power to you🚀🚀
Sir u are Just awesome, can u make video on... Like taking 32 bit why.. And also where to use it....As in most of the concept.. We are using.. It.. Taking upto 2^32...checking up to it.. Whole concept... ✨please make video on this!!!
Thanks a lot sir... Can you please make a dedicated video on bitmasking or say bit manipulation (if possible) and how to apply them on questions...it will be very helpful for us
if((num & temp) == 0) zcnt++; else ocnt++; if((num & temp) == 1) ocnt++; else zcnt++; Sir what is the difference between above two codes because first one giving the right answer while the second one is giving the wrong answer why ?? And Thanks for the amazing explanation❤❤
aisi aadat lag gyi h ki koi question serach krta hu is channel ka nam apne aap hi lga deta hu 😂😂 btw great explaination as always!! aap college student h kya??
If you have seem my DP Concepts & Qns Playlist, I have mentioned that i will be covering Hame Theory in it as well th-cam.com/play/PLpIkg8OmuX-JhFpkhgrAwZRtukO0SkwAt.html
Bhaiya i saw another approach in the discuss section where the person solved this by doing XOR with the numbers and running a single loop. Although i didn't understand the approach. // here is the code int one = 0; int two = 0; for(auto num: nums) { one = (one^num) | ~two; two = (two^num) | ~one; } return one; If possible please make a video and explain this approach.
@@nidhimishra2436 No I didn't see any video on that. I just tried to understand from the explanation they provided in Discuss section. But couldn't understand
I am aware of this approach but this is too tricky. It's not intuitive at all. It’s basically a very tricky approach. However my 3rd approach is Generalized approach. But I can make a video on this approach as well. But it's difficult to apply it in other problems
i am in tier-3 5th sem going to start .please advise me if I should revise love babbar sheet or should do I more questions?will love babbar sheet be enough
Hi there, If you are a fresher, I will suggest you to build your basics and practice more qns on each topic. Any sheet will be helpful if it covers multiple qns from each topic
I tried doing this for(int num:nums){ if((num & temp)==1){ ones++; }
if(ones%3==1){ result=(result | temp); } } and it didn't work . Since we are not using the count of zeros so we removed it , instead i checked for 1 like if that number had one in our 1
thanks the runtime for strange reasons was high so i checked other solutions class Solution { public int singleNumber(int[] nums) { int ones = 0; int twos = 0; for(int num : nums) { ones = ones ^ (num & ~twos); twos = twos ^ (num & ~ones); } return ones; } } are u aware about this approach ? seems interesting ..
thanks for the explanation it was help btw i do not think this is a good interview question as it depends upon a trick but its good that now i know it 🤣
Good qn. Please note that this will work for -ve numbers as well. Negative numbers are represented in two's compliment manner. So if nums is {-3, -3, -3, 1, 1, 1, 2} This will also work because in 2's compliment -3 will be represented as - '1111111111111101' And same will happen for other -3 in nuts. So anyways it will work.
hey i found this code, but didnt understand how it works. Can you please make a detailed video on this and explain? class Solution { public int singleNumber(int[] nums) { int ones = 0, twos = 0; for(int num : nums) { ones = (ones ^ num) & ~twos; twos = (twos ^ num) & ~ones; } return ones; } }
Wrote this in python, failing for negative inputs, can anyone solve the problem? class Solution: def singleNumber(self, nums: List[int]) -> int: res = 0 for k in range(32): count0 = count1 = 0 temp = 1
Loved the way you approached the Question
And Such a beautiful explanation
Thanks a lot 😊😇❤️
Today's GFG POTD too
You are born to be a teacher. 😇
Wow. You made my day 😇❤️
Thank you Ankit
Please note that this will work for -ve numbers as well.
Negative numbers are represented in two's compliment manner.
So if nums is {-3, -3, -3, 1, 1, 1, 2}
This will also work because in 2's compliment
-3 will be represented as - '1111111111111101'
And same will happen for other -3 in nuts.
So anyways it will work.
in python, this is failing for negative nos...
Hmm strange. Apologies as i have less visibility on python. Would you kindly share if you found the issue in Python ?
@@codestorywithMIK not yet, will share soon.
this is accurate running code for python to handle negative no
class Solution:
def singleNumber(self, nums: List[int]) -> int:
result = 0
is_neg = 0
for k in range(0, 32):
temp = (1
The way you made Graph easy for me, same way you make Bit manipulation a cake walk for me.
Thank you so much for such a neat explanation.
Respected MIK Sir,
The way you start explaining from basic (e.g. Left Shift) is so helpful even for beginner. Your video is made for all kind of viewers right from beginner level to advance level viewer. This helps beginner to progress to advance level.
Thank you so much for making our life easier 🙏🏼
bhai mtlb maza agya ekdm
Thank you so much Aman ❤️❤️
Great Explanation 😍
Thank you Anup 😇
everybody just giving their fancy solutions and they are not explaining it well. Thank you explaning in so simple detailed way.
❤️🙏
Bahut saare video dekhe but samajh nahi aarha tha but this video is more clear than crystal
I learnt one new approach of doing this Problem...really helpful
Glad to hear that 😇🙏
Very well explained ❤
Thank you so much Sahil ❤️❤️
thank you for this amazing explanation, hands down the best DSA teacher.
Amazing explanation please never stop uploading
best solution so far on this
bhai kya explain kiya hai 🙇♂
great explanation
Thank you so much ❤️🙏
loved your explanation thanks.
Thanks a lot ❤️❤️❤️
sir your teaching style is brilliant. all concepts cleared related to the bit manipulation,thank you, sir, 😊
Thank you for watching 😇🙏
class Solution {
public:
int singleNumber(vector& nums) {
unordered_map map;
for (int i = 0; i < nums.size(); i++){
map[nums[i]]++;
}
int ans=0;
for (auto x : map){
if(x.second==1) ans=x.first;
}
return ans;
}
};
Very clever of them to repeat it thrice instead of twice (cuz u know... If they had given twice, u could just xor the entire array to get that unique number)
Absolute ❤️❤️
@@codestorywithMIKbtw is O( 31 * n) is bigger than O (n * logn) ?
@@xiaoshen194 Let's say that n = INT_MAX in worst case.
i.e. n = 2147483647
Now, n*logn = n* log(2147483647) = n*31 approximately
Best explanation 😊
Thank you Mohit ❤️😇
Bhaiya third apporch is really good ❤
Indeed. Thanks a lot Umesh
Swaad aagya bhai kya hi explanation !💕
Thank you Tanuj ❤️❤️❤️
You are an artist bro ❤🔥
Thank you so much Prabhkirat ❤️❤️❤️
Nice Concept Explanation !!!
Thanks a lot ❤️❤️❤️
Very good explanation🔥✨
Thanks a lot 🙏❤️
nice explanation ;)
Thank you Dikshant ❤️😇
Thanks sir for explanation ,now let me code it on my own without looking at your code.
Sure 🙏❤️
nice sir
Thank you 😇❤️
The cleanest explanation i saw till now for this problem ❤
Thanks a lot
This is insanely well explained.
You are amazing
Awesome explanation ❤
It was a different solution than other standard solutions but it was brilliantly explained. It doesn't use any complex logic but it's a slow solution because of the time complexity of O(32*n) and beats only 25% of people. In my opinion, it's still better to use a slow simple solution rather than cramming a difficult solution so Hats off. More power to you🚀🚀
Means a lot. Thank you so much 🙏❤️
Masterpiece 🔥
wow
❤️❤️❤️😇
I think sorting in worst case takes O(NlogN),where logN
just now I solved this question by hashmap and your notification popped up:(
Not a problem Nikhil.
I am so glad you tried brute force approach as well.
It's always a good thing to learn more approaches
thank you sir , best way of explenation can you make one video on backtracking
kth bit can also be found out by doing right shift by K times and then & 1 to get the bit as 1 or 0
Sir u are Just awesome, can u make video on... Like taking 32 bit why.. And also where to use it....As in most of the concept.. We are using.. It.. Taking upto 2^32...checking up to it.. Whole concept... ✨please make video on this!!!
such a nice explanation sirrr . i just can't share my feelings with words. you are 💎 . Thank uh so much.
Means a lot Raunak ❤️❤️
This is lit bro 🔥 . Loved the simplicity of the explanation
👏👏🔥
Thanks a lot Ankit
W solution
🔥🔥🔥🔥
❤
Thanks a lot sir...
Can you please make a dedicated video on bitmasking or say bit manipulation (if possible) and how to apply them on questions...it will be very helpful for us
Sure thing.
Thanks a lot Saurav ❤️❤️
@@codestorywithMIK yes thanks a lot again.. waiting for the video ..the way u are explaining...uff I am just getting addicted to your explanation
for checking set bit (number>>k)&1==1 then kth bit of number is set . this is true always or not please tell me thank you sir
🔥🔥👍👍
This is today's GFG POTD (4th Jan, 2024) as well.
class Solution {
public:
int singleNumber(vector& nums) {
int ans = 0;
for(int i = 0;i
❤
LEGEND
if((num & temp) == 0) zcnt++;
else ocnt++;
if((num & temp) == 1) ocnt++;
else zcnt++;
Sir what is the difference between above two codes because first one giving the right answer while the second one is giving the wrong answer why ??
And Thanks for the amazing explanation❤❤
(num & temp) will not be equal to 1 always.
(num & temp) can be 000100 as well which is not 1.
@@codestorywithMIK Okay sir understood Thanks a lot sir extremely happy that I found your channel thanks sir for replying
Thank you so much ❤️❤️❤️
aisi aadat lag gyi h ki koi question serach krta hu is channel ka nam apne aap hi lga deta hu 😂😂
btw great explaination as always!!
aap college student h kya??
strangely I used the xor instead of or and result was same ... :D
Sincere request Bhaiya can u bring a playlist on game theory since your explanation is op❤
Sure thing ❤️❤️❤️
Thank you 😊 ❤️
If you have seem my DP Concepts & Qns Playlist, I have mentioned that i will be covering Hame Theory in it as well
th-cam.com/play/PLpIkg8OmuX-JhFpkhgrAwZRtukO0SkwAt.html
Alright thanks for considering it
++
Why we are calculating countZero if not using later?
Bhaiya i saw another approach in the discuss section where the person solved this by doing XOR with the numbers and running a single loop. Although i didn't understand the approach.
// here is the code
int one = 0;
int two = 0;
for(auto num: nums)
{
one = (one^num) | ~two;
two = (two^num) | ~one;
}
return one;
If possible please make a video and explain this approach.
Yeah I also saw it but they are so bad at explanation. I didn't get those.
@@wearevacationuncoverers from where you saw video?
yess if possible then explain this code as well !
@@nidhimishra2436 No I didn't see any video on that. I just tried to understand from the explanation they provided in Discuss section. But couldn't understand
I am aware of this approach but this is too tricky. It's not intuitive at all.
It’s basically a very tricky approach. However my 3rd approach is Generalized approach.
But I can make a video on this approach as well. But it's difficult to apply it in other problems
i am in tier-3 5th sem going to start .please advise me if I should revise love babbar sheet or should do I more questions?will love babbar sheet be enough
Hi there,
If you are a fresher,
I will suggest you to build your basics and practice more qns on each topic.
Any sheet will be helpful if it covers multiple qns from each topic
I tried doing this
for(int num:nums){
if((num & temp)==1){
ones++;
}
if(ones%3==1){
result=(result | temp);
}
}
and it didn't work . Since we are not using the count of zeros so we removed it , instead i checked for 1 like if that number had one in our 1
Because (num & temp) will not be equal to 1 always.
(num & temp) can be 000100 as well for example which is not equal to 1.
@@codestorywithMIK Thanks
bhaiya concept playlist kab aayegi (Bit Manipulation ka )
thanks
the runtime for strange reasons was high
so i checked other solutions
class Solution {
public int singleNumber(int[] nums)
{
int ones = 0;
int twos = 0;
for(int num : nums)
{
ones = ones ^ (num & ~twos);
twos = twos ^ (num & ~ones);
}
return ones;
}
}
are u aware about this approach ?
seems interesting ..
can u do this in O(N) and no space
thanks for the explanation it was help btw i do not think this is a good interview question as it depends upon a trick but its good that now i know it 🤣
❤️❤️❤️
bahiya by using map for -ve numbers answere is not correct.if possible then how.
How negative numbers are handled?
Good qn.
Please note that this will work for -ve numbers as well.
Negative numbers are represented in two's compliment manner.
So if nums is {-3, -3, -3, 1, 1, 1, 2}
This will also work because in 2's compliment
-3 will be represented as - '1111111111111101'
And same will happen for other -3 in nuts.
So anyways it will work.
@@codestorywithMIK Thanks! Got it...
Glad I could help 🙏
hey i found this code, but didnt understand how it works. Can you please make a detailed video on this and explain?
class Solution {
public int singleNumber(int[] nums) {
int ones = 0, twos = 0;
for(int num : nums) {
ones = (ones ^ num) & ~twos;
twos = (twos ^ num) & ~ones;
}
return ones;
}
}
public int singleNumber (int[]arr,int n){
int ones=0,twos=0;
for(int i=0;i
Map complexity ONlogn not ON
Can some one explain me why this code is not working for python
same here, if you have found the solution in python, please share
Wrote this in python, failing for negative inputs, can anyone solve the problem?
class Solution:
def singleNumber(self, nums: List[int]) -> int:
res = 0
for k in range(32):
count0 = count1 = 0
temp = 1
if you have found the solution in python, please share
class Solution:
def singleNumber(self, nums: List[int]) -> int:
result = 0
is_neg = 0
for k in range(0, 32):
temp = (1
this is accurate code for python to handle -ve nos as well
@@tanumittal899 thanks