xAI

Verified interview challenge

Repair a bank-account race condition

Make concurrent deposits safe without modifying or copying the existing account implementation.

Unlock with Full Access

The challenge

An existing deposit method reads a balance, waits and writes the updated value. Concurrent calls can interfere even though each deposit looks correct in isolation.

Build a compatible thread-safe account while reusing the original method. You cannot fix the problem by rewriting its body, so the exercise tests how to add coordination around behaviour you do not control.

What you'll practise

  • Lost-update diagnosis

    Explain which interleavings allow concurrent deposits to overwrite one another.

  • Safe composition

    Add synchronisation around existing behaviour while preserving the public interface.

Your coding workspacePreview
solution.pyPython 3.13
# Your implementation goes here

# Run examples and inspect results

# Full starter code included
Test cases

Run your code to see results.

Full instructions, starter code and test cases included with Full Access.