Skip to content

Commit

Permalink
Merge pull request fineanmol#5769 from sid123honey/patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
fineanmol authored Oct 5, 2023
2 parents 350fdc8 + 36a6583 commit dc25b06
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include <vector>
using namespace std;
int findTotalWays(vector<int> arr, int i, int s, int target)
{
if (s == target && i == arr.size())
return 1;
if (i >= arr.size())
return 0;
return findTotalWays(arr, i + 1, s + arr[i], target)
+ findTotalWays(arr, i + 1, s - arr[i], target);
}


int main()
{
vector<int> arr = { 1, 1, 1, 1, 1 };


int target = 3;

cout << findTotalWays(arr, 0, 0, target) << endl;

return 0;
}

0 comments on commit dc25b06

Please sign in to comment.