Programming Interview 12: Merge Two Sorted Arrays without additional memory

Step by step to crack Programming Interview questions 12: Merge Two Sorted Arrays into the larger array, given the large array has extra storage. Merge without additional memory

Solution:

1. Loop from end to beginning.

2. Keep track of two tail index values of two merged arrays.

3. Final-merged-tail position is equal to longTail+ShortTail+1 (both index start from 0!!)

4. If the shortTail is larger than or equal to 0 after merging, adding the remaining values to the merged array

Source...

View more

From: ProgrammingInterview

Related topics : longtail ad solutions