filmov
tv
LeetCode 88.Merge Sorted Array

Показать описание
Java : Leetcode 88. Merge Sorted Array
from Top Interview 150 List
Save this post for future and follow @tech_nub for more such learnings.
💡 Algorithm:
1. 2 Pointers approach
2. As nums1 has m elements followed by n 0's at the end, hence 1st array should have the final result by replacing those 0's.
3. We start filling from the end because if we start filling from the start, we would replace the existing elements in nums1.
4. Take 1st pointer at the end of nums1 (not at last position but at the end of the legit values) and 2nd pointer at the end of nums2
5. Edge Case : If any of the array is completely parsed, fill the rest of the values with the 2nd array's values
#datastructure #algorithms #faang #interview #tech_nub #preparation #java #python #meta #google #softwaredevelopment #developerlife #backenddeveloper #computerscience
#programmers #leetcode #leetcodesolutions
from Top Interview 150 List
Save this post for future and follow @tech_nub for more such learnings.
💡 Algorithm:
1. 2 Pointers approach
2. As nums1 has m elements followed by n 0's at the end, hence 1st array should have the final result by replacing those 0's.
3. We start filling from the end because if we start filling from the start, we would replace the existing elements in nums1.
4. Take 1st pointer at the end of nums1 (not at last position but at the end of the legit values) and 2nd pointer at the end of nums2
5. Edge Case : If any of the array is completely parsed, fill the rest of the values with the 2nd array's values
#datastructure #algorithms #faang #interview #tech_nub #preparation #java #python #meta #google #softwaredevelopment #developerlife #backenddeveloper #computerscience
#programmers #leetcode #leetcodesolutions