import Foundation
func findSmallestMissingNumber(_ arr: [Int]) -> Int {
let numSet = Set(arr) // Convert array to a set for fast lookup
for index in 1...(arr.max() ?? 0) + 1 {
if !numSet.contains(index) {
return index
}
}
return -1 // If no missing number is found
}
let arr = [3, 4, -1, 1]
print(findSmallestMissingNumber(arr))
/*
run:
2
*/