Largest value of K that a set of all possible subset | Function to find maximum count of consecutive integers from 0 in set S of all possible subset - sum ; Stores the maximum possible integer ; Sort the given array in non - decrasing order ; Iterate the given array ; If arr [ i ] <= X + 1 , then update X otherwise break the loop ; Return Answer ; Driver Code
function maxConsecutiveCnt ( arr ) { let X = 0 ; arr . sort ( function ( a , b ) { return a - b } ) for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] <= ( X + 1 ) ) { X = X + arr [ i ] ; } else { break ; } } return X + 1 ; } let arr = [ 1 , 1 , 1 , 4 ] ; document . write ( maxConsecutiveCnt ( arr ) ) ;