We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
i was still confused after reading this but my realization below helped clarify; so for those who still may be confused:
the whole idea of adding the recently popped 2nd stack element to the sum and removing the last 1st stack element if the sum is greater than the sum limit is to maintain the max count thus far.
therefore, the max count will never decrease and will only increase if either 1) we can add an element from the 2nd stack without removing from the sum or 2) removing an "added element from 1st stack" allows for 2 or more additional elements from 2nd stack.
Game of Two Stacks
You are viewing a single comment's thread. Return to all comments →
i was still confused after reading this but my realization below helped clarify; so for those who still may be confused:
the whole idea of adding the recently popped 2nd stack element to the sum and removing the last 1st stack element if the sum is greater than the sum limit is to maintain the max count thus far.
therefore, the max count will never decrease and will only increase if either 1) we can add an element from the 2nd stack without removing from the sum or 2) removing an "added element from 1st stack" allows for 2 or more additional elements from 2nd stack.