I have came across with interesting problem. Its a modification of subset sum problem.
For a given array of positive integers, We need to find the set of element containing maximum of elements and sum of these elements should be less than or equal to k.
Eg. 1.
Arr = [1,2,3,4,5,6,7,8,9,10], k = 15
output: [1, 2, 3, 4, 10]there are other possible outputs such as
[1, 2, 3, 5, 9], [1, 2, 3, 6, 8], [1, 2, 4, 5, 8], [1, 2, 4, 6, 7], [1, 3, 4, 5, 7] all above will be considered as correct answer.
Eg. 2
Arr = [1,2,3,4,6], k = 11
output: [1, 2, 3, 4]Constraints:
1 <= arr.length <= 200
1 <= arr[i] <= k <= 10^5
1 <= k <= 10^5
Can anyone help me solve this problem with minimal time & space complexity?