Commonly asked Interview Question- Merge Two Sorted Arrays(With and without extra space)

preview_player
Показать описание
Merge Two Sorted Arrays is an important interview question asked in companies like Microsoft, Adobe, Google, Amazon, Goldman Sachs, Apple, Facebook, IBM, Oracle, etc.

Topic - Arrays, Sorting

Question-
In this problem, we are given two sorted arrays of size N+M and M respectively. The task is to merge the arrays into one single array without extra space.

Logic -
1. The arr1 is of size N+M and arr2 is of size M, let variable k = N+M-1, i=n-1, and j=m-1.
2. The idea is to follow the same approach as the Merge process of Merge Sort.
a. Compare arr1[i] and arr2[j], until i and j are greater then equal to 0
i. if arr1[i] is greater then arr2[j], then in arr1[k] insert arr1[i]
ii. else in arr1[k] insert arr2[j]
b. If i is not zero then copy arr1[i] in arr1[k] till i becomes 0.
c. If j is not zero then copy arr2[j] in arr1[k] till j becomes 0.

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

The Explanation was very clear... even for beginners .THANK YOU !!

saumya
Автор

Explained very well, really understanble .

ummesalmakhatoon_cse_
Автор

Best session . i have a doubt on about the interview questions . But now it solved for arrays .

WnCD_Tech_channel
Автор

You have explained in the easiest and best way..

sonalisam
Автор

Thank you sir, Having confusion on arrays, Now I get clarity, Good Explanation Thanks a lot sir

JINKACHANDRAMOULI
Автор

Such a neat explanation with clean display..Great sir👍Thank you..

kaviyar
Автор

Best explanation ! Helped me to get a clear idea on sorting arrays !!

shanmugapriyam
Автор

Best explaination of the topic has been given 👍👍👍👍

chiragjain
Автор

Very informative video. Helped me to crack many coding competition problems with this...

abhijithbabu
Автор

Very well explained sir,
you make it simple to catch up!!

akhilnaseem
Автор

Content is helpful.
Well explained
Thanks for sharing 👍

medha
Автор

Great Explanation 🔥
Helped me clear many questions of Hackerrank!

vibhusharma
Автор

Thankyou Aveek sir for making the concept of arrays clear

chandanar
Автор

Thank you sir for making such an amazing video. I always had doubts regarding this topic. This video was really helpful for me in solving my doubts. looking forward to more such informative videos.

anumanjooran
Автор

Exellent explanation sir, thanks for sharing the question.It helps a lot in the merging and sorting of arrays.

darshanrajput
Автор

The concepts are taught so well, thanks for clearing all my doubts

sonukumarkeshri
Автор

Waooo, great explanation. My concepts are clear now

ur
Автор

Now the array topic is crystal clear 🤩... Thank you sir

kalyankarrahul
Автор

Explained clearly... even beginner can get this cleared, helped me solve in competitive coding.

prasannam
Автор

Thanks for this video, it helped me to gain more knowledge about array related problems and how to approach to the solution of the problem. Need more videos like this! Thank you 😀!

deysuman