Check if the given array can be reduced to zeros with the given operation performed given number of times | C # implementation of the approach ; Function that returns true if the array can be reduced to 0 s with the given operation performed given number of times ; Set to store unique elements ; Add every element of the array to the set ; Count of all the unique elements in the array ; Driver code
using System ; using System . Collections . Generic ; class GFG { public static bool check ( int [ ] arr , int N , int K ) { HashSet < int > unique = new HashSet < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { unique . Add ( arr [ i ] ) ; } if ( unique . Count == K ) { return true ; } return false ; } public static void Main ( string [ ] args ) { int [ ] arr = new int [ ] { 1 , 1 , 2 , 3 } ; int N = arr . Length ; int K = 3 ; if ( check ( arr , N , K ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }