Drill

ProblemsJava › reporting

Which month grew the most

mediumreportingArraysMathJava

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

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

Java 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

String biggestJump(List<Point> points) {
    
}

Worked examples

CallResult
biggestJump(Main.<Point>ls(new Point("jan", 100), new Point("feb", 150), new Point("mar", 160)))"feb"
biggestJump(Main.<Point>ls(new Point("jan", 100), new Point("feb", 110), new Point("mar", 120)))"feb"
biggestJump(Main.<Point>ls(new Point("jan", 100), new Point("feb", 90)))(String) null
biggestJump(Main.<Point>ls(new Point("jan", 100)))(String) null

Hint

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

Reference solution in Java
String biggestJump(List<Point> points) {
    String bestMonth = null;
    int bestJump = 0;
    for (int i = 1; i < points.size(); i++) {
        int jump = points.get(i).total - points.get(i - 1).total;
        if (jump > bestJump) { bestJump = jump; bestMonth = points.get(i).month; }
    }
    return bestMonth;
}

The same problem in another language

More reporting problems in Java