Question Bank

JavaScript Missing Numbers Finder: Two Approaches Quiz

Difficulty: Medium

Find missing integers between the min and max of an array, two ways (sort + gap-walk and Set diff over min..max), plus companions on the consecutive-1..n case and detecting duplicates.

Question Bank
/

JavaScript Missing Numbers Finder: Two Approaches Quiz

JavaScript Missing Numbers Finder: Two Approaches Quiz

Find missing integers between the min and max of an array, two ways (sort + gap-walk and Set diff over min..max), plus companions on the consecutive-1..n case and detecting duplicates.

Question Bank
Medium
JavaScript
4 questions
quiz
arrays
math
array-manipulation-patterns

227 views

1

Implement missingNumbers(arr) using SORT + a GAP WALK: sort numerically, then iterate from min to max and collect every integer absent from the sorted array.

Examples

Example 1:

Input: [1, 7, 3, 6]
Output: [2, 4, 5]
Explanation: Range is 1..7; missing integers are 2, 4, 5.

Example 2:

Input: [5, 0, -3, 2]
Output: [-2, -1, 1, 3, 4]
Explanation: Range is -3..5; missing integers are -2, -1, 1, 3, 4.