Find the smallest positive number missing from an unsorted array | Set 3 | C # program to find the smallest positive missing number ; Function to find the smallest positive missing number ; Default smallest Positive Integer ; Store values in set which are greater than variable m ; Store value when m is less than current index of given array ; Increment m when it is equal to current element ; Increment m when it is one of the element of the set ; Return the required answer ; Driver code ; Function call
using System ; using System . Collections . Generic ; class GFG { static int findMissingPositive ( int [ ] arr , int n ) { int m = 1 ; HashSet < int > x = new HashSet < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( m < arr [ i ] ) { x . Add ( arr [ i ] ) ; } else if ( m == arr [ i ] ) { m = m + 1 ; while ( x . Contains ( m ) ) { x . Remove ( m ) ; m = m + 1 ; } } } return m ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 3 , - 7 , 6 , 8 , 1 , - 10 , 15 } ; int n = arr . Length ; Console . WriteLine ( findMissingPositive ( arr , n ) ) ; } }