Check if the given array can be reduced to zeros with the given operation performed given number of times | 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
function check ( arr , N , K ) { var unique = new Set ( ) ; for ( var i = 0 ; i < N ; i ++ ) unique . add ( arr [ i ] ) ; if ( unique . size == K ) return true ; return false ; } var arr = [ 1 , 1 , 2 , 3 ] ; var N = arr . length ; var K = 3 ; if ( check ( arr , N , K ) ) document . write ( " " ) ; else document . write ( " " ) ;