#619 · Working with data · Advanced · Find and fix · 125 XP · about 20 min
A warehouse logs stock moves as (date, change) pairs. date is text in day/month/year form, such as '28/04/2026', and change is how many units came in (positive) or went out (negative). The log can be in any order.
stock_history(moves, start) should return a list of (date, level) pairs in date order, where level is the stock right after that move, beginning from start units. Moves on the same date stay in the order they have in the log. The caller's list must not change.
The code in the editor has two bugs. When every move falls in the same month the history is right, but across months the dates come out in the wrong order (2 May before 28 April). And testers noticed that their own list of moves looks different after calling the function.
stock_history([('03/05/2026', 4), ('12/05/2026', -2)], 10) # returns [('03/05/2026', 14), ('12/05/2026', 12)] stock_history([('02/05/2026', -3), ('28/04/2026', 10)], 5) # returns [('28/04/2026', 15), ('02/05/2026', 12)] stock_history([], 7) # returns []
moves has 0 to 10,000 pairs; days and months always have two digits, years four.First solves only, ranked by stars and then time.