**Just help me with the brute force approach only.**

Problem Name: Game of Two Stacks Problem Link

Note: I have converted vector to stack for twoStacks() function.

**Problem Description:** Alexa has two stacks of non-negative integers, stack A and stack B where index 0 denotes the top of the stack. Alexa challenges Nick to play the following game:

In each move, Nick can remove one integer from the top of either stack A or B stack.

Nick keeps a running sum of the integers he removes from the two stacks.

Nick is disqualified from the game if, at any point, his running sum becomes greater than some integer X given at the beginning of the game.

Nick’s final score is the total number of integers he has removed from the two stacks.

find the maximum possible score Nick can achieve (i.e., the maximum number of integers he can remove without being disqualified) during each game and print it on a new line.

For each of the games, print an integer on a new line denoting the maximum possible score Nick can achieve without being disqualified.

My Solution:

`int twoStacks(int x, stack<int> a, stack<int> b) { if(x < 0) { return -1; } int a_top = -1, b_top = -1, m1 = 0, m2 = 0; if(!a.empty()) { // Pop A a_top = a.top(); a.pop(); m1 = 1 + twoStacks(x - a_top, a, b); } if(!b.empty()) { // Pop B b_top = b.top(); b.pop(); if(a_top != -1) { a.push(a_top); } m2 = 1 + twoStacks(x - b_top, a, b); } return max(m1, m2); } `