Skip to content

Instantly share code, notes, and snippets.

@basil2style
Created September 14, 2020 11:26
Show Gist options
  • Save basil2style/8add8895683a72448e6f31855b5bfaca to your computer and use it in GitHub Desktop.
Save basil2style/8add8895683a72448e6f31855b5bfaca to your computer and use it in GitHub Desktop.
Given range of 1 to N and an array of unique integers that are within that range, return the missing integers not found in the array
@arr = [1,3,4]
@n = 4
@missing_nums = []
(1..@n).each do |i|
if !@arr.include?(i)
@missing_nums.append(i)
end
end
puts @missing_nums
arr = [1,3,4]
n = 4
function missingNumber(n, arr) {
var missingNums = [];
for (var i = 1; i <= n; i++) {
if (!arr.includes(i)) {
missingNums.push(i);
}
}
return missingNums;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment