Minimum count of numbers required from given array to represent S | Function to find the minimum elements required to get the sum of given value S ; Condition if the sequence is found ; Condition when no such sequence found ; Calling for without choosing the current index value ; Calling for after choosing the current index value ; Function for every array ; Driver Code
function prletAllSubsetsRec ( arr , n , v , sum ) { if ( sum == 0 ) { return v . length ; } if ( sum < 0 ) return Number . MAX_VALUE ; if ( n == 0 ) return Number . MAX_VALUE ; let x = prletAllSubsetsRec ( arr , n - 1 , v , sum ) ; v . push ( arr [ n - 1 ] ) ; let y = prletAllSubsetsRec ( arr , n , v , sum - arr [ n - 1 ] ) ; v . pop ( v . length - 1 ) ; return Math . min ( x , y ) ; } function prletAllSubsets ( arr , n , sum ) { let v = [ ] ; return prletAllSubsetsRec ( arr , n , v , sum ) ; } let arr = [ 2 , 1 , 4 , 3 , 5 , 6 ] ; let sum = 6 ; let n = arr . length ; document . write ( prletAllSubsets ( arr , n , sum ) ) ;