Interview Question: Merge Arrays

Sdílet
Vložit
  • čas přidán 13. 09. 2024
  • Coding interview question from www.byte-by-byt...
    In this video, I show how to merge two sorted arrays.
    Do you have a big interview coming up with Google or Facebook? Do you want to ace your coding interviews once and for all? If so, Byte by Byte has everything that you need to go to get your dream job. We've helped thousands of students improve their interviewing and we can help you too.
    Stuck on Dynamic Programming? Check out our free ebook: www.dynamicprogrammingbook.com
    Need an interview coach? Send in an application: www.byte-by-byte.com/coaching
    You can also find me on
    Twitter: / bytebybyteblog
    Facebook: / bytebybyteblog
    Email: sam@byte-by-byte.com

Komentáře • 18

  • @mukundsridhar4250
    @mukundsridhar4250 Před rokem

    I think the zeros in the first array first need to be moved to the front of the array. Here the contents of array B will always be greater than a since a[aIndex] will always be lesser than b[bIndex].
    Thank you for all your amazing videos and great work :)

  • @dephc0n1
    @dephc0n1 Před 6 lety +2

    Thank you for your content! Your videos are a perfect resource to get some additional algorithms in my toolbox. Keep up the good work.

  • @vyshnavramesh9305
    @vyshnavramesh9305 Před 4 lety

    liked the light blue color of the logo. It distinguishes itself from other videos

  • @pascal3889
    @pascal3889 Před 7 lety +2

    Hey Sam,
    I think int []a = {1,3,5,0,0,0} array will have a length 6. So we can have aIndex = (a.length - b.length) -1, bIndex = b.length - 1 and mergeIndex = a.length -1. Let me know your thoughts on this. Great video as always!

    • @ByteByByte
      @ByteByByte  Před 7 lety +1

      Yeah you're definitely right. Good catch

  • @RuanFamily
    @RuanFamily Před 7 lety +1

    Love your videos. Thank you.
    You don't need to explicitly pass aLength, and bLength, because bLength = sizeof(b)/sizeof(b[0]). aIndex = aSize - bSize - 1;

  • @indrapriyanka2733
    @indrapriyanka2733 Před 5 lety

    hey, nice video. what if we replace the second array in the empty place of the first array(in this case 0,0,0) and then do a simple sort of A ?

  • @carabrennan9407
    @carabrennan9407 Před 6 lety

    Could you just put the B array into the a array based on where the zeros are and then sort it?

    • @ByteByByte
      @ByteByByte  Před 6 lety

      That would work as well, but what would be the time complexity of doing that?

    • @carabrennan9407
      @carabrennan9407 Před 6 lety

      Factorial?

    • @ByteByByte
      @ByteByByte  Před 6 lety +1

      What is the time complexity of sorting in general?

    • @dephc0n1
      @dephc0n1 Před 6 lety

      @Subhash Mannava exactly! This algorithm runs in linear time and uses no additional space. Unless you count the pointers.

  • @chaoschao9432
    @chaoschao9432 Před 5 lety

    really clear.

  • @nivedhapadmanabhan1794
    @nivedhapadmanabhan1794 Před 5 lety +1

    actually its incorrect, now when you copy the from A[aIndex] to A[mergerIndex] you need to set A[aIndex] as min value, otherwise it wont work.