Drill

ProblemsC# › reporting

Which month grew the most

mediumreportingArraysMathC#

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

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

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public string BiggestJump(List<Point> points) {
    
}

Worked examples

CallResult
BiggestJump(new List<Point> { new Point("jan", 100), new Point("feb", 150), new Point("mar", 160) })"feb"
BiggestJump(new List<Point> { new Point("jan", 100), new Point("feb", 110), new Point("mar", 120) })"feb"
BiggestJump(new List<Point> { new Point("jan", 100), new Point("feb", 90) })null
BiggestJump(new List<Point> { new Point("jan", 100) })null

Hint

Start from index 1 and keep the best strictly-greater difference, so ties keep the first one.

Reference solution in C#
public string BiggestJump(List<Point> points) {
    string bestMonth = null;
    int bestJump = 0;
    for (int i = 1; i < points.Count; i++) {
        int jump = points[i].Total - points[i - 1].Total;
        if (jump > bestJump) { bestJump = jump; bestMonth = points[i].Month; }
    }
    return bestMonth;
}

The same problem in another language

More reporting problems in C#