Log inBook a Demo
OptimizeMidBackendAuto-graded

Speed up a slow /report endpoint

The report gets much slower as the event log grows; make it scale linearly and keep every number exactly the same.build_report(store) in report.py rolls up page views per session from an event log. The numbers are right, but double the log and the work far more than doubles. The store counts every operation (store.ops, printed by python3 report.py), so you can measure it directly. Make the work grow linearly with the number of events, within 20 operations per event, and keep the report exactly as it is, session order included. Change build_report and leave dataset.py as it is: the grader runs your code on its own copy of the store, and on other event logs of the same shape (other session ids, other view counts), so the report must come from the events, not from patterns in today's data.
30 min
Python

Goals

  • On the 600-event log, build_report stays within the operation budget.
  • The operation count grows linearly with the size of the event log.
  • Within the operation budget, build_report returns a report identical to today's, session order included, at every log size and on other event logs of the same shape.

What it measures

Measuring firstFinding where the operations come from before changing any code.
Algorithmic fixA rewrite that changes how the work grows with the size of the log.
No regressionsKeeping the report identical, checked at more than one log size.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

30 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo