You are viewing a single comment's thread. Return to all comments →
{ stack<int> a1; stack<int> b1; int val = 0; int tmp = 0; int t = 0; for (int i = a.size() - 1; i >= 0; i--) { a1.push(a[i]); } for (int i = b.size() - 1; i >= 0; i--) { b1.push(b[i]); } while (tmp <= maxSum && (!a1.empty() || !b1.empty())) { val = t; if (!a1.empty() && (b1.empty() || a1.top() <= b1.top())) { tmp += a1.top(); a1.pop(); t += 1; } else if (!b1.empty()) { tmp += b1.top(); b1.pop(); t += 1; } } return val; }
what is the problem
Seems like cookies are disabled on this browser, please enable them to open this website
Game of Two Stacks
You are viewing a single comment's thread. Return to all comments →
what is the problem