Categories
interview

Find Identical Node in DOM Tree

Categories
interview

Find Median from Data Stream

Categories
interview

Merge Sorted Array

/**
 * @param {number[]} nums1
 * @param {number} m
 * @param {number[]} nums2
 * @param {number} n
 * @return {void} Do not return anything, modify nums1 in-place instead.
 */

var merge = function(nums1, m, nums2, n) {
  let index = m + n - 1;
  m--;
  n--;
  while (m >= 0 && n >= 0) {
    if (nums1[m] >= nums2[n])
      nums1[index--] = nums1[m--];
    else
      nums1[index--] = nums2[n--];
  }
  while (index >= 0)
    nums1[index--] = m >= 0 ? nums1[m--] : nums2[n--];
};

const arr = [1, 3, 4, , , ];
merge(arr, 3, [1, 2, 4], 3);
console.log(arr);
// Output: [1, 1, 2, 3, 4, 4]

Demo

Categories
interview

Merge K Sorted Lists

Demo

Categories
interview

Merge Two Sorted Lists

Demo