79138499

Date: 2024-10-29 18:24:29
Score: 0.5
Natty:
Report link

I tried to use a two-pointer algorithm but realized that I need 3 pointers in this case.

var merge = function(nums1, m, nums2, n) {
    let i = m - 1;  // Pointer for the last initialized element in nums1
    let j = n - 1;  // Pointer for the last element in nums2
    let k = m + n - 1;  // Pointer for the last position in nums1

    // Iterate backwards and fill nums1 from the end
    while (j >= 0) {
        if (i >= 0 && nums1[i] > nums2[j]) {
        nums1[k] = nums1[i];
        i--;
    } else {
        nums1[k] = nums2[j];
        j--;
    }
    k--;
}

return nums1;

};

Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Olena Potiatynyk