Which month grew the most
A board slide calls out the month with the largest jump in revenue over the month before it.
- Compare each month with the one directly before it, in the order given.
- Only increases count; a month that fell is not a jump.
- On a tie, the earlier month wins.
- Fewer than two months, or no increase anywhere, gives null.
biggest_jump(points: list<Point>) → string?
Where you start
def biggest_jump(points: list[Point]) -> str | None:
Worked examples
| Call | Result |
|---|---|
biggest_jump([Point(month="jan", total=100), Point(month="feb", total=150), Point(month="mar", total=160)]) | "feb" |
biggest_jump([Point(month="jan", total=100), Point(month="feb", total=110), Point(month="mar", total=120)]) | "feb" |
biggest_jump([Point(month="jan", total=100), Point(month="feb", total=90)]) | None |
biggest_jump([Point(month="jan", total=100)]) | None |
Hint
Start from index 1 and keep the best strictly-greater difference, so ties keep the first one.
Reference solution in Python
def biggest_jump(points: list[Point]) -> str | None:
best_month = None
best_jump = 0
for i in range(1, len(points)):
jump = points[i].total - points[i - 1].total
if jump > best_jump:
best_jump, best_month = jump, points[i].month
return best_month