Find first k natural numbers missing in given array | C # code for the above approach ; Program to print first k missing number ; Creating a hashmap ; Iterate over array ; Iterate to find missing element ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { static void printmissingk ( int [ ] arr , int n , int k ) { Dictionary < int , int > d = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { d . Add ( arr [ i ] , arr [ i ] ) ; } int cnt = 1 ; int fl = 0 ; for ( int i = 0 ; i < ( n + k ) ; i ++ ) { if ( ! d . ContainsKey ( cnt ) ) { fl += 1 ; Console . Write ( cnt + " ▁ " ) ; if ( fl == k ) break ; } cnt += 1 ; } } static public void Main ( ) { int [ ] arr = { 1 , 4 , 3 } ; int n = arr . Length ; int k = 3 ; printmissingk ( arr , n , k ) ; } }