Google Interview Question - Bit Manipulation | Single Number II
Single Number II is a coding interview question asked in Google Interviews.
Question:
Given an array of integers, every element appears thrice except for one which occurs once.
Find that element which does not appear thrice.
Note: Your algorithm should have a linear runtime complexity.
Could you implement it without using extra memory?
----------------------------------------------------------------------------------------------------
To get notified of all the new videos, subscribe - kzread.info?sub_co...
Learn more about Scaler - www.scaler.com/?Yo...
Follow us on Linkedin - / scaler
----------------------------------------------------------------------------------------------------
Пікірлер: 41
we can also solve these without taking array for count. int Solution::singleNumber(const vector &A) { int res=0; for(int i=0;i
After searching so many videos, I finally came across this video which is crisp and clear. Thank you!
great explanation!
Thank you for this video which has made me understand the solution of this problem so easily.
I like this method better than the ones and twos method which isn't intuitive at all. Here's the code -- ``` class Solution: def singleNumber(self, nums: List[int]) -> int: answer = 0 for i in range(32): temp = 0 for n in nums: temp += n & (1
Great approach ma'am
Very nicely explained.
Thank you mam.Make more videos
thanks mam.explained well
nice explaination
Yep its clear, Thank youuu ;)
What is that software used to write ? In Windows PAINT we can't write so neatly ? Is it mac or linux and what software/application is used?
@saichakrapani2890
5 ай бұрын
Ipad
It fails for negative numbers
what happen if we take negative value in array? your solution does not work on negative values
@scikick
2 жыл бұрын
It surely does. You just need to check the 32nd bit and convert it to proper negative if necessary.
could you share code for this question?
Right!
RIGHT!
the complexity will be o(b*n) where b is the number of bits in numbers in array of size n?
@SCALER
2 жыл бұрын
Hey Avnish, yes, that's right. Thanks for sharing your input! :)
i think using xor will be much faster.
👌
how the time complexity is order of O(n) it should be order of O(sizeOfArray * log(maxElement)) and this complexity is called order of O(nlogn);
@julianmoraes3106
3 жыл бұрын
log(maxElement) can at most be 31 if you have an array of ints, so you can treat it as a constant which makes it O(n) where n is the length of your array
will it not fail for negative numbers?
@maneshwarsingh8688
4 жыл бұрын
Right
@Crack_interview_with_sim
2 жыл бұрын
It will fail
Right?
@aditya234567
3 жыл бұрын
right :p
Time is O(n*32)
This won't work for negative numbers
Code?
Guys please use an extra variable and set it's values after counting the number of one's and taking modulus with 3.Use left shift operator for setting all the values.This way the parity can be handled.
@utkarshgupta5817
4 жыл бұрын
Hi Shubham, we are considering all the 32 bits of all integer numbers (complete integer range) so can you please explain why it will not work for negative numbers? Because I think it should work.
@shubhambhatt7171
4 жыл бұрын
@@utkarshgupta5817 I am sorry for my mistake.I rectified my mistake.Instead of setting bits in a variable ,I was storing in an array and calculating the value.
Best Solution to this problem. Right? :P
@amreshgiri4933
2 жыл бұрын
sorting one is better.
how is approach better than sorting the array...sorting would take O(nlogn) but this approach take O(n*32) ......so on avg case sorting is better
Can you use plain English? Right