-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathways.java
More file actions
61 lines (29 loc) · 729 Bytes
/
Copy pathways.java
File metadata and controls
61 lines (29 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package recursion;
public class ways {
public static int helper(int input[], int target, int csum, int i) {
if (i == input.length) {
if (csum == target)
return 1;
else
return 0;
}
//recursive calls
//include element +
int add = helper(input, target, csum + input[i], i + 1);
//include element -
int sub = helper(input, target, csum - input[i], i + 1);
// not included
int exc = helper(input, target, csum, i + 1);
return add + sub + exc;
}
public static int numberOfWays(int[] input, int sum) {
//Your Code goes here
int ans= helper(input,sum,0,0);
if(sum==0){
return ans-1;
}
else{
return ans;
}
}
}