Created
September 14, 2020 11:26
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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