Find duplicate in an array of N+1 integers |Q11| Love Babbar DSA sheet

Sdílet
Vložit
  • čas přidán 2. 11. 2020
  • #coding #competitiveprogramming #interviewquestions #dsaseries
    In this video I have explained the 11th problem.
    Time Complexity = O(N)
    Space Complexity = O(1)
    Love Babbar DSA sheet : drive.google.com/file/d/1FMdN...
    Hope you like it. If have any doubt then just comment down below.
    LIKE | SHARE | SUBSCRIBE

Komentáře • 81

  • @adityajain1205
    @adityajain1205 Před 2 lety +30

    The problem states we have to solve it without modifying the array

  • @_pralhadbehera6341
    @_pralhadbehera6341 Před rokem +2

    I have one doubt that it's time complexity will be o(n^2)
    So it will not applicable
    Instead that we will use brute force approach (linear search)??
    If any one agree to my doubt plz like and if any one has solution to my doubt them plz reply

  • @a_storyy_teller
    @a_storyy_teller Před 3 lety

    you explain in very good way

  • @mohd.anassiddiqui1521
    @mohd.anassiddiqui1521 Před 2 lety +11

    common mistake: you will take "N" which is less than the array's greatest element.
    So take elements which is less than the size of the array.
    Read ques carefully:
    Given an array of integers arr containing n + 1 integers where each integer is in the range
    [1, n] inclusive.

  • @SushilaDevi-zp9le
    @SushilaDevi-zp9le Před 3 lety +3

    Osm 👍👍

  • @masqueradeee
    @masqueradeee Před 3 lety

    Nicely explained 👍

  • @prasannathapa1024
    @prasannathapa1024 Před 3 lety +2

    🔥🔥

  • @harshidatanku6561
    @harshidatanku6561 Před 2 lety

    what if we have values in the array greater than the len of array

  • @SushilaDevi-zp9le
    @SushilaDevi-zp9le Před 3 lety +2

    Very good 👍👍

  • @akashade7996
    @akashade7996 Před 11 měsíci

    Dry run is not understand please explain .i am not understand in dry run concept the array is when adding with the size

  • @107_kumarpurushottam6
    @107_kumarpurushottam6 Před 3 lety

    awesome

  • @mihirkumar5857
    @mihirkumar5857 Před 3 lety +1

    ❤️❤️❤️❤️

  • @yashsaini3331
    @yashsaini3331 Před 2 lety

    Thank You very much bhai

  • @devarithish7459
    @devarithish7459 Před 3 lety +11

    8/6 is greater than 1

    • @vishalsonkaria7643
      @vishalsonkaria7643 Před 3 lety +5

      he taking array of integer type so only integer part will be saved that is 1

    • @shrustipal284
      @shrustipal284 Před 2 lety

      right it won't be greater than 1

  • @prabaljana9714
    @prabaljana9714 Před 9 měsíci

    If the element is 0 ..then what to do .. because if divided then get 0 also

  • @Rohit-qp1ye
    @Rohit-qp1ye Před 3 lety

    Bro I am trying this question in python form past 1 hour but I am stucked can I get help from you

  • @yogeshsakle9128
    @yogeshsakle9128 Před 3 lety +5

    You Speak in striver tone

  • @everyone8057
    @everyone8057 Před rokem

    leetscode says without modifying the array but have modified it

  • @madhav9223
    @madhav9223 Před 3 lety +1

    Very well explained bro. Your way of explaining is superb . Keep it up

    • @mohitkumar557
      @mohitkumar557 Před 2 lety

      abe bsdk isme kya superb tha. isne toh array ko alter kiya jab ki question me array read only tha.

  • @shubhamchavan1387
    @shubhamchavan1387 Před 3 lety +1

    Thank you!

  • @saiquakhan3850
    @saiquakhan3850 Před 3 lety

    🙏

  • @prashantkhadye7858
    @prashantkhadye7858 Před 2 lety +1

    But why you’re diving by array by n why the a[i]/n > 1

  • @amannegi8256
    @amannegi8256 Před 2 lety +2

    array modification isnt allowed

  • @mohitkumar557
    @mohitkumar557 Před 2 lety

    what is this ? The question was not to alter the array or It was read only......

  • @ayushprakash3890
    @ayushprakash3890 Před 2 lety

    hey man can you explain the bucketing apporach

  • @lappu_sa_sachin_seema
    @lappu_sa_sachin_seema Před 3 lety

    have you made any playlist for solution of love babbar dsa sheet ?

  • @ADITYAGAIKWAD
    @ADITYAGAIKWAD Před 3 lety +1

    What is the return statement in the answer in gfg?

  • @prithvichetty15
    @prithvichetty15 Před 3 lety +9

    so 8/6 is greater than 1 so what does that mean ? does it mean 1 is repeated or what ?

  • @programmingspace916
    @programmingspace916 Před 3 lety +2

    Explain Clearly bro

  • @jeevaananth6194
    @jeevaananth6194 Před 3 lety +10

    What if some elements of array is greater than size of array?
    This code won't work, right?

    • @CodeLibrary
      @CodeLibrary  Před 3 lety +9

      In question, it was mentioned that all the values will be between 0 to n so here we can use the array as a hashmap as I mentioned in video but if the values are greater than n then we cannot use array as a hashmap

    • @jeevaananth6194
      @jeevaananth6194 Před 3 lety +2

      @@CodeLibrary got it bro, thanks!

    • @balasubramaniam199
      @balasubramaniam199 Před 2 lety +5

      @@CodeLibrary problem states that need to be solved without modifying the array

  • @deekshithpranav1619
    @deekshithpranav1619 Před 3 lety

    bro but in the leetcode problem we are assuming only one duplicate is there. But in the video there are two duplicates for three.

    • @Aishwarya_Shetty
      @Aishwarya_Shetty Před 3 lety +2

      Even i assumed that there would be only one duplicate, so i submitted the solution for that, but there were testcases in which numbers are repeated more than twice.

    • @alliswellbrochill9937
      @alliswellbrochill9937 Před 2 lety

      I think they told about a particular number not the no of times it gets repeated , so only 1 number in the array gets repeated and it can repeat any times

  • @SoftwareDeveloper86
    @SoftwareDeveloper86 Před 3 lety

    bhaiya concept to samaj aa gya kese hua, but vo % wali line samaj nhi ai kya ho raha hai vaha

  • @TheSandsplash
    @TheSandsplash Před 3 lety

    Should not you consider elements can be close to 10^5

  • @chanduchandrakanth5131
    @chanduchandrakanth5131 Před 3 lety +5

    Bro but we can do this problem by using for loop also
    Void duplicate (int a[ ], int n){
    Sort(a, a+n);
    for(int i=0; i

  • @akashsrivastavavines5021
    @akashsrivastavavines5021 Před 2 lety +4

    8/6 is greater than 1 😂

  • @lokeshnegi5051
    @lokeshnegi5051 Před 3 lety

    bro cant we just sort the array and then check for arr[i]==arr[i+1]?

    • @hanseldsilva2393
      @hanseldsilva2393 Před 3 lety

      Complexity of sorting is O(n logn) which is above the expected O(n)

    • @ishankbansal9239
      @ishankbansal9239 Před 3 lety

      Beta brute force karte reh jaaoge zindagi mein

    • @lokeshnegi5051
      @lokeshnegi5051 Před 3 lety +4

      @@ishankbansal9239 to bhai sidha best se hi krna start krte ho kya sir ap fr to apko utube khol lna chiye.

    • @abdheshkumar7699
      @abdheshkumar7699 Před 2 lety

      @@lokeshnegi5051 mene bhi aisa hi kia tha

  • @vishalsonkaria7643
    @vishalsonkaria7643 Před 3 lety +1

    in making o(1) space you made ,time o(n^3)

  • @BadNews17
    @BadNews17 Před rokem

    bhai kaisa samjha rha hai? neend mein ho kya?
    "15/6 is greater than 2".. kaise? 15/6 is 2

  • @shubhamsingh5899
    @shubhamsingh5899 Před 3 lety +4

    Try with input 1,3,3,4,5 , It will return a wrong answer

    • @redboy6889
      @redboy6889 Před 3 lety +1

      This is incorrect input.... the array size is n+1 and can have values only till n. In your case, the size is 5 and I see a 5 in it.

  • @prashantsandilya6197
    @prashantsandilya6197 Před 3 lety +2

    Array modify ho rha bhai..bina array ko modify kro wo solution dhoondh rha tha

    • @CodeLibrary
      @CodeLibrary  Před 3 lety +1

      If you don't want to modify array then use a separate hashmap for frequency of array elements, then space complexity will become O(N)....so to reduce the space complexity to O(1) I am using array as a hashmap

    • @prashantsandilya6197
      @prashantsandilya6197 Před 3 lety +5

      But still u r modifying na. Dont wnt extraa space n also dont wnt to modify ths array.. i mean i ws looking for tht explanation man...using floyd cycle detection.no modification, no extraa space , no hash map, no hash table , no set ...like tht.understood bro? Link list kind of approach...internally doun everythn.

  • @mayankdhiman5355
    @mayankdhiman5355 Před 2 lety +2

    class Solution {
    public int findDuplicate(int[] nums){

    int[] a=new int[nums.length];
    for(int i=0;i

  • @vaibhavbhardwaj2500
    @vaibhavbhardwaj2500 Před rokem

    Sasta Love Babbar..😄

  • @premmane9816
    @premmane9816 Před 2 lety

    bro array must not be modified

  • @rajkumarchawla6807
    @rajkumarchawla6807 Před 3 lety +2

    May the worst one

  • @masoomzaid225
    @masoomzaid225 Před 2 lety

    bhai time complexity name ki bhi cheez h dekh to le question me duniya bhr ke loop ni chalane ek me krna h

  • @tabishansari6350
    @tabishansari6350 Před 2 lety

    are kehna kya chahte ho 😑

  • @opinions892
    @opinions892 Před 2 lety

    Not effective solution...

  • @harshwardhanchaube706
    @harshwardhanchaube706 Před 2 lety

    at least read the question b4 making a vedio

  • @sachinupreti7159
    @sachinupreti7159 Před 2 lety

    Bakwaas

  • @akhileshmishra5559
    @akhileshmishra5559 Před rokem

    Bad explanation , didn't understand anything...

  • @suvigyabasnotra7378
    @suvigyabasnotra7378 Před 2 lety +3

    You don't make right choice of vocabulary when speaking English. So a lot of times your sentences don't explain what what you're actually thinking in that moment. That wastes a lot of time just trying to understand the approach and your code.
    The solution: Just speak in Hindi. At least your choice of words would explain the thing accurately there. For English viewers, you can add subtitles.