Drill

ProblemsPython › reporting

Which month grew the most

mediumreportingPython

A board slide calls out the month with the largest jump in revenue over the month before it.

biggest_jump(points: list<Point>) → string?

Solve it in the editor →

Where you start

def biggest_jump(points: list[Point]) -> str | None:
    

Worked examples

CallResult
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

The same problem in another language

More reporting problems in Python