Merge Sorted Array | Live Coding with Explanation | Leetcode - 88

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ก.ย. 2024

ความคิดเห็น • 119

  • @AlgorithmsMadeEasy
    @AlgorithmsMadeEasy  3 ปีที่แล้ว +11

    We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!!
    Questions you might like:
    ✅✅✅[ Tree Data Structure ] : th-cam.com/play/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls.html
    ✅✅✅[ Graphs Data Structure ] : th-cam.com/play/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C.html
    ✅✅✅[ December Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA.html
    ✅✅✅[ November Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e.html
    ✅✅✅[ August Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe.html
    ✅✅✅July Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC-.html
    ✅✅✅June Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2xIfpptnCvUtKrUcod2zAKG.html
    ✅✅✅May Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e.html
    ✅✅✅Cracking the Coding Interview - Unique String: th-cam.com/play/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE.html
    Struggling in a question??
    Leave in a comment and we will make a video!!!🙂🙂🙂

  • @sauravdhar1696
    @sauravdhar1696 2 ปีที่แล้ว +29

    This is probably the best explaination of this problem on youtube, Thank you for this

    • @AlgorithmsMadeEasy
      @AlgorithmsMadeEasy  2 ปีที่แล้ว

      Thank you!! 😀
      Do share and subscribe if this video helped you!! 🙂

  • @steeck1
    @steeck1 3 ปีที่แล้ว +9

    Thank you for this explanation! I see there are many ways to try and solve this problem. This way and the animations you used really helped me to properly conceptualize everything and understand your code.

    • @AlgorithmsMadeEasy
      @AlgorithmsMadeEasy  3 ปีที่แล้ว +2

      Really glad you liked it !!! Thanks for your comment !!

  • @nos44-
    @nos44- 2 ปีที่แล้ว +3

    you just managed to give the best explanation of this problem with the most optimal solution and its edge cases, space time complexity within just 5 mins ... brilliant

  • @sravansunkara9145
    @sravansunkara9145 หลายเดือนก่อน

    3 years!!! And this is still the best solution. THANK YOU.

  • @rdubb77
    @rdubb77 ปีที่แล้ว +2

    Super clear. I often shake my head at the solutions in LC, they nearly always are more complicated than they need to be and you just proved that again.

  • @headofthetable5653
    @headofthetable5653 2 ปีที่แล้ว +3

    best explanation for this question forever.

  • @abhinavawasthi7818
    @abhinavawasthi7818 ปีที่แล้ว +1

    Much simpler code with best explanation!

  • @santimoyrana7790
    @santimoyrana7790 2 ปีที่แล้ว +2

    Such a beautiful explaination. My all doubts are cleared now.

  • @sivabalakrishnanramasamy7843
    @sivabalakrishnanramasamy7843 หลายเดือนก่อน

    Excellent Explanation. Thank you

  • @manokamnasingh
    @manokamnasingh 2 ปีที่แล้ว +2

    this is the best explanation of this problem 💯

  • @abarnoraha8805
    @abarnoraha8805 2 หลายเดือนก่อน +1

    This is the best explanation

  • @PitBit
    @PitBit 9 หลายเดือนก่อน +1

    Nice and concise explanation with good animations. Thank you! :)

  • @FRAMEDSKATEKREW69
    @FRAMEDSKATEKREW69 2 ปีที่แล้ว +1

    I liked this video approach, very glad I found this video.

  • @kartikkathuria7506
    @kartikkathuria7506 2 ปีที่แล้ว +1

    Best Solution and Explaination of this question

  • @aanisnoor229
    @aanisnoor229 2 ปีที่แล้ว +1

    Such an easy to follow explanation, thank you!

    • @bts2287
      @bts2287 2 ปีที่แล้ว

      Hi....I have a douth...actually iam a beginner so...my douth is
      How this code output gets printed without print

    • @shashankvashishtha935
      @shashankvashishtha935 2 ปีที่แล้ว +1

      @@bts2287 this is on leetcode platform, we just have to put our condiotns in this the backend process will automatically be executed.

    • @bts2287
      @bts2287 2 ปีที่แล้ว

      @@shashankvashishtha935 thankyou👍

  • @amanrathore3610
    @amanrathore3610 ปีที่แล้ว +1

    very well explained with visual thank you so much for this amazing content

  • @jaishreesaraswat3629
    @jaishreesaraswat3629 3 ปีที่แล้ว +2

    Very good visualization ...great work !

  • @prashantbalotra
    @prashantbalotra 5 หลายเดือนก่อน +1

    Great explanation ❤

  • @oqant0424
    @oqant0424 2 ปีที่แล้ว +1

    what an explaination ......literally thanks a lot

  • @tusharnain6652
    @tusharnain6652 2 ปีที่แล้ว +2

    Best!

  • @Leyka-ot1mx
    @Leyka-ot1mx 3 หลายเดือนก่อน +1

    Excellent work ka💥

  • @ana-mariagarlau798
    @ana-mariagarlau798 3 ปีที่แล้ว

    hi! thank you so much for this elegant solution. i had to repeatedly do it on paper in order to comprehend why this works but the idea is great!

    • @jenethar7628
      @jenethar7628 2 ปีที่แล้ว

      Hey one douth how this code will generate output without print

  • @mysteriousocean3206
    @mysteriousocean3206 3 ปีที่แล้ว +1

    littlrly great explanation and also ppt presentation

  • @minarezkalla4403
    @minarezkalla4403 ปีที่แล้ว +1

    thank you 😍 this channel always helpful

  • @sagnikghoshcr7
    @sagnikghoshcr7 ปีที่แล้ว

    Greatest approach for this problem

  • @CodeBeans.i0s
    @CodeBeans.i0s 2 ปีที่แล้ว +1

    Very good explanation ... Thanks a lot .

  • @Zezemint
    @Zezemint 2 ปีที่แล้ว +1

    I'm a little confused about what m is. In the instructions, it says that m is the size of nums1. If that were the case, shouldn't m be 6 in our example here?

    • @OurBrainHurtsALot
      @OurBrainHurtsALot 8 หลายเดือนก่อน +1

      From what I gather is the amount of non-zero numbers in nums1. This problem is confusing

  • @poojitharavuri2943
    @poojitharavuri2943 3 ปีที่แล้ว +1

    Awesome explanation! loved it!

  • @Akash-dg3lv
    @Akash-dg3lv 22 วันที่ผ่านมา

    It shows me array index out of bound exception what do I do

  • @Rahulyadav-lv7dh
    @Rahulyadav-lv7dh 2 ปีที่แล้ว +1

    Excellently explained

  • @darshankalathiya8667
    @darshankalathiya8667 2 ปีที่แล้ว +1

    good animation and exprenation mem Thank You :) .

  • @paniknoob6439
    @paniknoob6439 3 หลายเดือนก่อน

    why> p>=0 and q>=0 ?

  • @sproutboot
    @sproutboot 2 ปีที่แล้ว

    2:03 what's i? i =m+n-1.
    Thank you very well explained

  • @milindbadekar3503
    @milindbadekar3503 2 ปีที่แล้ว +1

    KEEP WORKING THANK YOU

  • @rohhittz
    @rohhittz 6 หลายเดือนก่อน +1

    Very well good optimal approach explanation 👏! You are voice so cute💗!Thank you..

  • @vansh9857
    @vansh9857 ปีที่แล้ว

    When looking at the question how do you perform that kind of a solution in your mind ?

  • @Yazy-tf1sv
    @Yazy-tf1sv 2 หลายเดือนก่อน

    What I don't understand is why we don't need to write any "append" or "push" or any code that actually changed the value from 0 to the new value. It's just changed? Am I missing something?

    • @AlgorithmsMadeEasy
      @AlgorithmsMadeEasy  2 หลายเดือนก่อน

      Since it is an array, we can directly update the value.

  • @rajkumardongre3085
    @rajkumardongre3085 2 ปีที่แล้ว +1

    Maza aya..

  • @dhairyashiil
    @dhairyashiil 2 ปีที่แล้ว +1

    Thank You !

  • @omkarpatil9886
    @omkarpatil9886 ปีที่แล้ว +1

    hey..thanks

  • @soumikpaul6503
    @soumikpaul6503 2 ปีที่แล้ว +1

    Thanks

  • @jenethar7628
    @jenethar7628 2 ปีที่แล้ว +1

    This question may sound stupid since iam a beginner....so my question is
    🔸️how this output will generate without print ....?

    • @mehulsingh1216
      @mehulsingh1216 2 ปีที่แล้ว +1

      In leetcode we just have to write the method(which contains main algorithm), printing and taking input is done by leetcode only...hope it will clear your doubt...(even in questions it is also written "you don't have to print anything"....

    • @jenethar7628
      @jenethar7628 2 ปีที่แล้ว

      @@mehulsingh1216 okay👍 , Thank you🤗

  • @mridul1075
    @mridul1075 3 ปีที่แล้ว +1

    thankyou sister

  • @balivadasairaghavahemanth1466
    @balivadasairaghavahemanth1466 3 ปีที่แล้ว +1

    Nicely done ✔

  • @daanishsarguru3044
    @daanishsarguru3044 3 ปีที่แล้ว +1

    Thanks guys

  • @amcreations9192
    @amcreations9192 2 ปีที่แล้ว +1

    Thank u ❣️

  • @Progresser436
    @Progresser436 3 ปีที่แล้ว +1

    Thanks 👍

  • @gokulnaathb2627
    @gokulnaathb2627 2 ปีที่แล้ว +1

    Beautiful

  • @systemforge
    @systemforge 2 ปีที่แล้ว +1

    Amazing

  • @solar679
    @solar679 2 ปีที่แล้ว

    Great explanation but how is the space complexity constant time since we are adding elements to back of the array ?

    • @ajaykmr8684
      @ajaykmr8684 2 ปีที่แล้ว

      But we are not taking extra space to add the elements right? We are just using the already given array to add elements. Whenever there is a new requirement for space, space complexity increases. Here we could have used a 3rd array of size m+n-1 to add the elements which would've increased our space complexity to O(n). But instead we used the given array which made our space comp to O(1)

  • @amanprajapati3417
    @amanprajapati3417 ปีที่แล้ว +1

    class Solution {
    public:
    void merge(vector& nums1, int m, vector& nums2, int n) {
    int p1 = 0;
    int p2 = 0;
    for(int i = 0; i < m+n; i++)
    {
    if(n == 0 ) break;
    if(m == 0) nums1[0] = nums2[0];

    if(i < m)
    {
    if(nums1[i]

    • @amanprajapati3417
      @amanprajapati3417 ปีที่แล้ว

      btw your 2 pointer approach is the best, loved that explaination
      ♥♥♥

  • @EternalCoders
    @EternalCoders 8 หลายเดือนก่อน

    can you please explain in C++

  • @ak27129
    @ak27129 ปีที่แล้ว

    time limit exceeded man

  • @trustGod9834
    @trustGod9834 3 ปีที่แล้ว

    HI, how to solve the same question with this kind of parameter ?
    public void merge(List< Integer>nums1, int m, List nums2, int n)

    • @AlgorithmsMadeEasy
      @AlgorithmsMadeEasy  3 ปีที่แล้ว

      list and array both are index based so that will be same as this problem.

  • @pramodwadile6076
    @pramodwadile6076 ปีที่แล้ว

    Time Limit Exceeded at the time of run.

  • @xinchenzou4558
    @xinchenzou4558 2 ปีที่แล้ว +1

    Why I can not figure out this solution on my own :( So clever!!

  • @louischou6780
    @louischou6780 3 ปีที่แล้ว

    why is p2 >= 0 in the while loop condition instead of p1>=0 in the while loop condition?

    • @rahulmaurya597
      @rahulmaurya597 3 ปีที่แล้ว +2

      Because nums1 always greater then nums2 to thats why we take the validation of nums2 (p2>=0)

    • @vidhi_bhatt
      @vidhi_bhatt 2 ปีที่แล้ว +1

      because in the question it is given that we need to modify nums1, ie. size of nums1 will always be greater than that of nums2

  • @amruthaa5876
    @amruthaa5876 3 ปีที่แล้ว

    Why is the time complexity O(KlogK)? Can you please explain 1:02

    • @AmitSingh-xg1tm
      @AmitSingh-xg1tm 3 ปีที่แล้ว +2

      Because she said we can sort the merged array using arrays.sort. Java uses quicksort internally in Arrays.sort method, which has the time complexity of nlogn.

  • @sanjaychaharnaturevlogs7077
    @sanjaychaharnaturevlogs7077 6 วันที่ผ่านมา

    Error code

  • @sugyanpatnaik2098
    @sugyanpatnaik2098 ปีที่แล้ว

    getting ArrayIndexOutOfBoundsException error
    int p1 = m - 1, p2 = n - 1, i = m + n - 1;
    while (p2 >= 0) {
    if (p1 >= 0 && nums1[p1] > nums2[p2]) {
    nums1[i--] = nums1[p1--];
    } else {
    nums1[i--] = nums2[p2--];
    }
    }
    System.out.println(Arrays.toString(nums1));
    }

  • @codehustler7412
    @codehustler7412 2 ปีที่แล้ว +1

    Awesome content! Subscriber++;

  • @Adilkhan-lw5fm
    @Adilkhan-lw5fm 2 ปีที่แล้ว

    Hey Siri.😄

  • @ishwarshelke128
    @ishwarshelke128 3 ปีที่แล้ว +1

    thanks

    • @AlgorithmsMadeEasy
      @AlgorithmsMadeEasy  3 ปีที่แล้ว

      Most welcome!! 🙂 Do check out our latest giveaway video and participate!! 🙂