OptimizeMidBackendAuto-graded
Speed up a /report endpoint that rescans everything
Redesigning a slow calculation so it keeps pace as data grows, without altering any reported value, is the task.The/report endpoint builds a per-session roll-up of page views from an event log. It works, and it is the hot path in every profile — because it runs nested linear scans. For each event it scans a list to check whether the session is new, and for every new session it scans the entire log again to sum that session's views. Rewrite it so the result is identical and the work grows linearly with the log rather than quadratically.30 min
python
You're done when
- The number of operations falls within the budget for the reference log.
- The work scales linearly with the size of the event log rather than quadratically.
- The rewrite avoids rescanning the log per session.
What it measures
Debugging and profilingIdentifying the nested scan responsible for the cost instead of micro-optimising around it.
Performance optimizationReplacing repeated scans with a single pass and the right lookup structure.
Refactoring without regressionPreserving the exact output while changing the algorithm underneath, verified at more than one size.
Your environment
Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards
Start this lab
30 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo