Count of distinct integers in range [ 1 , N ] that do not have any subset sum as K | Java program for the above approach ; Function to find maximum number of distinct integers in [ 1 , N ] having no subset with sum equal to K ; Declare a vector to store the required numbers ; Store all the numbers in [ 1 , N ] except K ; Store the maximum number of distinct numbers ; Reverse the array ; Print the required numbers ; Driver Code ; Given Input ; Function Call
import java . util . * ; class GFG { static void findSet ( int N , int K ) { ArrayList < Integer > a = new ArrayList < Integer > ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { if ( i != K ) a . add ( i ) ; } int MaxDistinct = ( N - K ) + ( K / 2 ) ; Collections . reverse ( a ) ; for ( int i = 0 ; i < MaxDistinct ; i ++ ) System . out . print ( a . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int N = 5 , K = 3 ; findSet ( N , K ) ; } }