Skip to interview prep
Apexed
Problem list121 / 143

121. Summarize Endpoint Latencies

MediumSorting and ranks

Each sample is [endpoint, nonnegative latency]. Collect the latencies for each endpoint and compute the nearest-rank percentile.

For an endpoint with n samples sorted in ascending order, return the sample at one-based rank ceil(n × percentile / 100). Return [endpoint, latency] pairs in the order the endpoints first appear.

Example 1

Input: samples = [["search",40],["status",2],["search",10],["search",50],["status",1]], percentile = 50
Output: [["search",40],["status",1]]

Example 2

Input: samples = [["up",5],["up",1],["up",1],["up",6]], percentile = 75
Output: [["up",5]]

Constraints

  • At most 100,000 samples.
  • Percentile is an integer from 1 to 100. Latencies are integer milliseconds.

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs in an isolated browser sandbox. Progress and submissions are saved on this device.

Summarize Endpoint Latencies — coding interview practice — Apexed