Determining the Last Remaining Ball's Color
Last ball color after drawing process is a medium quant interview question on Brain Teasers.
This teaser describes a probabilistic-looking ball-removal process where the composition of colors in a bag keeps changing as you repeatedly draw and replace balls according to fixed color rules. At first glance it feels like a messy stochastic evolution, but the twist is that the final outcome is actually deterministic and depends only on the initial mix of colors. Variants like this are popular in brainteaser rounds and sometimes in quant trading or hedge fund interviews to test whether candidates can see through apparent randomness to a structural property that fully determines the last remaining ball.
Solving it leans heavily on spotting and formalizing an invariant, typically something like the parity or modular behavior of a count that evolves in a simple, trackable way under each allowed operation. An interviewer is looking for someone who doesn't brute-force states or simulate but instead abstracts the transformation rules, checks all possible move types systematically, and proves that the chosen quantity behaves predictably. Clear reasoning about why the process must terminate, and why the final color is uniquely determined by the invariant, is also central.
What it tests
This problem class is governed by invariant analysis, where you identify a property of the system that remains unchanged (or changes in a predictable way) through each operation. Here, the key invariant is the parity of a particular count (such as the number of red balls), which is preserved or predictably altered by the rules of the process. Invariant-based problems often involve repeated transformations, and the challenge is to find a quantity whose behavior under those transformations is simple enough to track. The reason this works is that, regardless of the complexity of the process, the invariant acts as a constraint on the system's possible states, often determining the final outcome. The principle holds because the rules either leave the invariant unchanged or flip it in a controlled way, so the initial value of the invariant dictates the end state.
Practise this question with written feedback, or hear it in a spoken mock interview.
Get started free