MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / recur

Method recur

CountNumberOfMaximumBitwise-ORSubsets.java:14–29  ·  view source on GitHub ↗
(int index, int nums[], int curOr, int targetOr,Integer dp[][])

Source from the content-addressed store, hash-verified

12 // tc: n*targetOr
13 // sc: n*targetOr
14 public int recur(int index, int nums[], int curOr, int targetOr,Integer dp[][]){
15 //base case
16 if(index == nums.length){
17 return (curOr == targetOr)?1:0;
18 }
19 //check if already solved
20 if(dp[index][curOr]!=null){
21 return dp[index][curOr];
22 }
23 // O(2^n)
24 //pick
25 int pickCount = recur(index+1, nums, curOr | nums[index], targetOr,dp);
26 //no pick
27 int noPickCount = recur(index+1, nums, curOr, targetOr,dp);
28 return dp[index][curOr] = pickCount + noPickCount;
29 }
30}

Callers 1

countMaxOrSubsetsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected