Merge Two Sorted Lists II

Given two sorted integer arrays A and B, merge B into A as one sorted array.
Thoughts: 1st attempt

14 June 2022

  • 0:00 The name of the question tells me it's going to be an easy problem, but the β€œII” in its name tells me otherwise. Let me give it a try.

  • 1:29 I wanted to do it under an unrealistic amount of time, so I cheated and used sorting. It is a solution anyway.

  • 2:58 OK, now I'll think of better ways to do it besides sorting. I still have lots of time. I'll spend about 30 minutes on this.

  • 8:00 I solved it using a third vector. I think that's it from my side. I'll look at the solution.

  • 16:00 My two pointer solution was the most optimal one. Great.

Using Sorting

Time Complexity: O(nlog⁑n)O(n\log n)​

Space Complexity: O(m+n)O(m+n)

Using a third vector and two pointers

Time Complexity: O(m+n)O(m + n)​

Space Complexity: O(m+n)O(m + n)​

Last updated