You are given an array arr[] of N integers including 0. The task is to find the smallest positive number missing from the array.
Example 1:
Input: N = 5 arr[] = {1,2,3,4,5} Output: 6
Smallest Positive missing number in Java
class Solution { //Function to find the smallest positive number missing from the array. static int missingNumber(int arr[], int size) { // Your code here HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); for(int i=0;i<size;i++){ if(arr[i]>0){ hm.put(arr[i],1); } } for(int i=1;i<=size;i++){ if(!hm.containsKey(i)) return i; } return size+1; } }
Disclaimer: This problem(Smallest Positive Missing Number) is originally created by GeeksforGeeks. Codesagar only provides a solution for it. This solution is only for Educational and learning purposes.