Ping histogram
EasyOnline Assessment
Summarize the response times a status page recorded as a histogram.
The bucket edges are given in milliseconds in increasing order: e0 < e1 < ... < ek. They define k + 2 buckets, in this order:
0up toe0, written"0-<e0 - 1>"e0up toe1, written"<e0>-<e1 - 1>", and so on for every pair of neighbouring edgesekand above (the overflow bucket), written"<ek>+"
A bucket includes its lower edge and excludes its upper edge, so a 250 ms reading with an edge at 250 belongs to the bucket that starts at 250. If there are no edges at all, there is a single bucket "0+".
Each reading is a string: "<n>ms" is n milliseconds, "<n>s" is n whole seconds (1 s = 1000 ms), and "timeout" is a request that never answered. Timeouts are not part of any range: they are counted on a final line of their own.
Input: edges, a list of integers, and readings, a list of strings.
Output: a list of strings, one per bucket in the order above, each written "<label>: <count>", followed by the line "timeout: <count>". Print every bucket, including empty ones, and always print the timeout line, even when its count is 0.
Example 1
- Input:
- [[100,250,500],["40ms","100ms","249ms","250ms","1s","20ms","499ms","500ms"]]
- Output:
- ["0-99: 2","100-249: 2","250-499: 2","500+: 2","timeout: 0"]
- Explanation
- Every bucket includes its lower edge and excludes its upper edge. 100ms goes to 100-249 (not 0-99), 249ms stays in 100-249, 250ms moves up to 250-499 and 500ms is already in the overflow bucket 500+. One reading of 1s is 1000ms, also overflow.
Example 2
- Input:
- [[1000,2000],["1s","2s","999ms","timeout","1500ms","timeout"]]
- Output:
- ["0-999: 1","1000-1999: 2","2000+: 1","timeout: 2"]
- Explanation
- Readings in seconds are converted first: 1s is 1000ms and goes to 1000-1999, 2s is 2000ms and goes to the overflow bucket. 999ms is the last value of 0-999. The two timeouts are counted on their own line, not in any range.
Example 3
- Input:
- [[1,2,3],["0ms","0s","3ms","3ms","1ms","5ms"]]
- Output:
- ["0-0: 2","1-1: 1","2-2: 0","3+: 3","timeout: 0"]
- Explanation
- With edges 1, 2 and 3 the buckets are 0-0, 1-1, 2-2 and 3+. Empty buckets are still printed, and the timeout line is printed even when its count is 0.
Constraints
0 <= edges.length <= 20;edgesis strictly increasing and every edge is between1and1000000 <= readings.length <= 500; every reading is"<n>ms","<n>s"or"timeout"with0 <= n <= 100000