Modify array by making all array elements equal to 0 by subtracting K ^ i from an array element in every i | Function to check whether all array elements can be made zero or not ; Stores if a power of K has already been subtracted or not ; Stores all the Kth power ; Iterate until X is less than INT_MAX ; Traverse the array arr [ ] ; Iterate over the range [ 0 , M ] ; If MP [ V [ j ] ] is 0 and V [ j ] is less than or equal to arr [ i ] ; If arr [ i ] is not 0 ; If i is less than N ; Otherwise , ; Driver code
function isMakeZero ( arr , N , K ) { let MP = new Map ( ) ; let V = [ ] ; let X = 1 ; let i ; while ( X > 0 && X < Number . MAX_VALUE ) { V . push ( X ) ; X *= K ; } for ( i = 0 ; i < N ; i ++ ) { for ( let j = V . length - 1 ; j >= 0 ; j -- ) { if ( MP . has ( V [ j ] ) == false && V [ j ] <= arr [ i ] ) { arr [ i ] -= V [ j ] ; MP . set ( V [ j ] , 1 ) ; } } if ( arr [ i ] != 0 ) break ; } if ( i < N ) return " " ; else return " " ; } let arr = [ 8 , 0 , 3 , 4 , 80 ] ; let N = arr . length ; let K = 2 ; document . write ( isMakeZero ( arr , N , K ) ) ;