Subset sum K [Recursion]
https://www.geeksforgeeks.org/subset-sum-problem-dp-25/
class Solution {
static boolean isSumK(int[] nums, int curin, int curSum) {
if(curSum==0) {
return true;
}
if(curin<0) {
return false;
}
return isSumK(nums, curin-1, curSum-nums[curin])
|| isSumK(nums, curin-1, curSum);
}
static Boolean isSubsetSum(int N, int arr[], int sum) {
// code here
return isSumK(arr, N-1, sum);
}
}
Comments
Post a Comment