text: Find the subsequence with given sum in a superincreasing sequence | Function to find the required subsequence ; Current element cannot be a part of the required subsequence ; Include current element in the required subsequence So update the sum ; Prlet the elements of the required subsequence ; If the current element was included in the subsequence ; Driver code
code: function findSubSeq ( arr , n , sum ) { for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( sum < arr [ i ] ) arr [ i ] = - 1 ; else sum -= arr [ i ] ; } for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != - 1 ) document . write ( arr [ i ] + " " ) ; } } let arr = [ 17 , 25 , 46 , 94 , 201 , 400 ] ; let n = arr . length ; let sum = 272 ; findSubSeq ( arr , n , sum ) ;