Drill

ProblemsJava › monitoring

The p95 of a batch of latencies

mediummonitoringSortingArraysMathJava

Dashboards quote p95 rather than the average, so one pathological request does not hide behind a thousand fast ones.

percentileValue(values: list<int>, rank: int) → int

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

int percentileValue(List<Integer> values, int rank) {
    
}

Worked examples

CallResult
percentileValue(Main.<Integer>ls(1, 2, 3, 4, 5), 50)3
percentileValue(Main.<Integer>ls(1, 2, 3, 4, 5), 100)5
percentileValue(Main.<Integer>ls(1, 2, 3, 4, 5), 1)1
percentileValue(Main.<Integer>ls(10, 20, 30, 40, 50, 60, 70, 80, 90, 100), 95)100

Hint

In integers, ceil(rank * n / 100) is (rank * n + 99) / 100. Then subtract one for a zero-based index.

Reference solution in Java
int percentileValue(List<Integer> values, int rank) {
    if (values.isEmpty() || rank < 1 || rank > 100) return 0;
    List<Integer> s = new ArrayList<>(values);
    Collections.sort(s);
    int pos = (rank * s.size() + 99) / 100;
    return s.get(pos - 1);
}

The same problem in another language

More monitoring problems in Java