LeetCode Interview Problem - Merge Sorted Array

preview_player
Показать описание
#keeponcoding #tech #programming

*** SUBSCRIBE TO THE CHANNEL ***

-----------------------------------

*** SUPPORT ME ON PATREON ***

-----------------------------------

*** INSTAGRAM ***
Рекомендации по теме
Комментарии
Автор

Man you need to do more leetcode problems . You're such a great teacher

chetanpatteparapu
Автор

hey your tutorials are way better than others

1) you speak clear American, very easy to understand

2) you're not an annoying know it all like some others

neohubris
Автор

Man this was a clean and straight forward approach. Better than leetcode solutions

Edmundlu
Автор

Thank You! Finally someone who does a coding walkthrough with the approach I was trying to implement. So now I see where I was tricked up.

woodylucas
Автор

wow. this old videos shows how far he has come

arpit
Автор

best solution imo. makes sense, easy to read, fast.

cloud
Автор

Nailed it. I'm just a beginner and I approached this problem with the merge fn of mergeSort. Please do more videos and share coding tips. Thank you.

venkateshrajendran
Автор

Wow you made this make so much sense. Thanks!

Ziggy
Автор

you explain the solution like you are the author of the problem
keep on coding and making videos like this
I'm sure it helped and will help a lot of people ❤🤟

mohammedfalih
Автор

I understood your point except for one where the size of the second array is 0 and then you are just filling the rest of the gaps in the nums1 array with it's own elements and if the example is nums1= [1, 2, 3, 0, 0, 0] and given that nums2 is null then the result is somewhat like
nums1= [1, 2, 3, 1, 2, 3]
Please explain I think I am missing out some detail here

tanishktripathi
Автор

You can break out of loop if(n < 0).

vishal
Автор

Any thoughts on why going from front to back isn't practical?

basedonprinciple
Автор

what if we insert 2nd arrays elements randomly into the first array and use sort method

abhiram
Автор

Can someone explain how the m and n pointers work? I don't understand why he put m--; n--; at the beginning of the program. does that bring m to the back of nums1 and n to the back of nums2?

ognimoddd
Автор

You rushed through the meat of the problem, between 2.20 - 2.33. Also, didn't explain why you insert an additional copy of 3, when the element of the 2nd list to insert is 2. I think that was a typo.

athens
Автор

i converted this solution into python it says time limit exceeds
class Solution:
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
"""
Do not return anything, modify nums1 in-place instead.
"""
m=-1
n=-1

index = len(nums1)-1
while index >= 0:
if m<0:
nums1[index]=nums2[n]
n=-1
elif n<0:
nums1[index] = nums1[m]
m=-1
else:
if nums1[m]>nums2[n]:
nums1[index]=nums1[m]
m=-1
else:
nums1[index]=nums2[n]
n=-1
index=-1



help me please

sandeepvaid
Автор

hey! thanks for an awesome video. can u suggest some other coding sites for the preparation of companies like google amazon facebook?

swati
Автор

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

trustGod
Автор

Solution doesn't hold for test case
[0, 0, 0, 0, 0, 0, 0, 0]
3
[2, 5, 6]
3
index should be "index=m+n-1" instead of "index=nums1.length-1"
thanks!

ammarshaikh