Advertisement
Smallest Positive Missing Number
JavaView on GFG
Smallest Positive Missing Number.java
Java
class Solution {
// Function to find the smallest positive number missing from the array.
public int missingNumber(int[] arr) {
Set<Integer> set = new HashSet<>();
for (int num : arr) {
if (num > 0)
set.add(num);
}
int smallNum = 1;
while (set.contains(smallNum))
smallNum++;
return smallNum;
}
}Advertisement
Was this solution helpful?