Largest value of K that a set of all possible subset | C ++ program for the above approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxConsecutiveCnt ( vector < int > arr ) { int X = 0 ; sort ( arr . begin ( ) , arr . end ( ) ) ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( arr [ i ] <= ( X + 1 ) ) { X = X + arr [ i ] ; } else { break ; } } return X + 1 ; } int main ( ) { vector < int > arr = { 1 , 1 , 1 , 4 } ; cout << maxConsecutiveCnt ( arr ) ; return 0 ; }