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

  • @VikashKumar-ug5jx
    @VikashKumar-ug5jx4 жыл бұрын

    we can also solve these without taking array for count. int Solution::singleNumber(const vector &A) { int res=0; for(int i=0;i

  • @bengaluruhudgi5432
    @bengaluruhudgi54324 жыл бұрын

    After searching so many videos, I finally came across this video which is crisp and clear. Thank you!

  • @shashikant123kadam
    @shashikant123kadam4 жыл бұрын

    great explanation!

  • @AbhijeetMuneshwar
    @AbhijeetMuneshwar2 жыл бұрын

    Thank you for this video which has made me understand the solution of this problem so easily.

  • @scikick
    @scikick2 жыл бұрын

    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

  • @ayushgarg5929
    @ayushgarg59294 жыл бұрын

    Great approach ma'am

  • @dev-skills
    @dev-skills3 жыл бұрын

    Very nicely explained.

  • @seenivasagans5399
    @seenivasagans53994 жыл бұрын

    Thank you mam.Make more videos

  • @VikashKumar-ug5jx
    @VikashKumar-ug5jx4 жыл бұрын

    thanks mam.explained well

  • @sachinprasad2220
    @sachinprasad22204 жыл бұрын

    nice explaination

  • @ankitgoyal8556
    @ankitgoyal85564 жыл бұрын

    Yep its clear, Thank youuu ;)

  • @AmitKumar-we8dm
    @AmitKumar-we8dm Жыл бұрын

    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

    @saichakrapani2890

    5 ай бұрын

    Ipad

  • @just_another_curious_guy
    @just_another_curious_guy4 жыл бұрын

    It fails for negative numbers

  • @shwetankdixit8797
    @shwetankdixit87973 жыл бұрын

    what happen if we take negative value in array? your solution does not work on negative values

  • @scikick

    @scikick

    2 жыл бұрын

    It surely does. You just need to check the 32nd bit and convert it to proper negative if necessary.

  • @muthukamalan.m6316
    @muthukamalan.m63162 жыл бұрын

    could you share code for this question?

  • @mohitkalra9329
    @mohitkalra93293 жыл бұрын

    Right!

  • @Hyperian
    @Hyperian3 жыл бұрын

    RIGHT!

  • @avnishsingh3006
    @avnishsingh30062 жыл бұрын

    the complexity will be o(b*n) where b is the number of bits in numbers in array of size n?

  • @SCALER

    @SCALER

    2 жыл бұрын

    Hey Avnish, yes, that's right. Thanks for sharing your input! :)

  • @rishabhsingh4317
    @rishabhsingh43173 жыл бұрын

    i think using xor will be much faster.

  • @HimanshuSingh-ob9qo
    @HimanshuSingh-ob9qo2 жыл бұрын

    👌

  • @ShubhamKumar-rt8nb
    @ShubhamKumar-rt8nb3 жыл бұрын

    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

    @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

  • @yjj410
    @yjj4104 жыл бұрын

    will it not fail for negative numbers?

  • @maneshwarsingh8688

    @maneshwarsingh8688

    4 жыл бұрын

    Right

  • @Crack_interview_with_sim

    @Crack_interview_with_sim

    2 жыл бұрын

    It will fail

  • @agarwalvivek101
    @agarwalvivek1014 жыл бұрын

    Right?

  • @aditya234567

    @aditya234567

    3 жыл бұрын

    right :p

  • @mujtabaarfat717
    @mujtabaarfat7173 жыл бұрын

    Time is O(n*32)

  • @Crack_interview_with_sim
    @Crack_interview_with_sim2 жыл бұрын

    This won't work for negative numbers

  • @VISHAL-ko4rt
    @VISHAL-ko4rt3 жыл бұрын

    Code?

  • @shubhambhatt7171
    @shubhambhatt71714 жыл бұрын

    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

    @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

    @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.

  • @sunilkumawat7959
    @sunilkumawat79593 жыл бұрын

    Best Solution to this problem. Right? :P

  • @amreshgiri4933

    @amreshgiri4933

    2 жыл бұрын

    sorting one is better.

  • @Shailswap14
    @Shailswap143 жыл бұрын

    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

  • @mamurdjuraev1260
    @mamurdjuraev12604 жыл бұрын

    Can you use plain English? Right