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

Popular posts from this blog

Getting Started With MEAN App Development with AngularJs , ExpressJs , NodeJs and MongoDB.

B. Dreamoon and WiFi :calculate no. of ways : recursive solution (branch and bound )

A. Dreamoon and Stairs : minimum steps to reach : recursion solution.