Latency Bucket Counter
Reported by candidates from Datadog's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Strip away the monitoring jargon and this Datadog problem is a histogram with an overflow bin. It was reported in February 2026, and it's the kind of OA question that looks like a warm-up but punishes sloppy edge handling. You get a sorted latency array, a bucket count, and a width. Return counts per bucket. The last bucket swallows everything at or above (numOfBuckets - 1) * bucketWidth. If you've got an invite for this one, the pattern is counting with integer division. If your head goes blank mid-assessment, StealthCoder runs invisibly as a safety net and gives you the solution live.
The problem
You are given an array latencies of positive integers sorted in ascending order, an integer numOfBuckets, and an integer bucketWidth. Each latency is measured in milliseconds. Return an array of numOfBuckets counts. For every bucket index i from 0 through numOfBuckets - 2, bucket i covers the inclusive range [i * bucketWidth, (i + 1) * bucketWidth - 1]. The last bucket is an overflow bucket: it contains every latency greater than or equal to (numOfBuckets - 1) * bucketWidth. The returned value at index i must equal the number of latencies assigned to bucket i. Function countLatenciesInBuckets(latencies: int[], numOfBuckets: int, bucketWidth: int) → int[] Examples Example 1 latencies = [6,7,50,100,110] numOfBuckets = 11 bucketWidth = 10 return = [2,0,0,0,0,1,0,0,0,0,2] Latencies 6 and 7 fall in bucket 0, latency 50 falls in bucket 5, and latencies 100 and 110 fall in the last overflow bucket. Example 2 latencies = [12,22,38,41,120,131,250] numOfBuckets = 6 bucketWidth = 40 return = [3,1,0,2,0,1] The first bucket covers 0 through 39, so it contains 12, 22, and 38. Values 120 and 131 share bucket 3, while 250 goes to the overflow bucket. Example 3 latencies = [1,2,3,4,5] numOfBuckets = 5 bucketWidth = 10 return = [5,0,0,0,0] Every latency is between 0 and 9, so all five values fall in bucket 0. Constraints 1 <= latencies.length <= 10^5 1 <= latencies[i] <= 10^9 latencies is sorted in ascending order. 1 <= numOfBuckets <= 10^4 1 <= bucketWidth <= 10^6
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is one line: bucket index = min(latency / bucketWidth, numOfBuckets - 1) using integer division. Loop once, increment the count at that index, done. That's O(n) time and O(numOfBuckets) space. The sorted input is a hint toward two pointers or binary search per boundary, but you don't need it. A single pass is fine for 10^5 elements. The common pitfalls are off-by-one on the overflow bucket, forgetting the min clamp so you index past the array, and overflow worries with values up to 10^9 times widths (the division avoids multiplying, so you're safe). Also check numOfBuckets = 1, where everything is overflow. Test example 3 mentally: all values under 10 land in bucket 0. If the clamp or the boundary logic slips under pressure, StealthCoder is the hedge during the live OA, reading the problem and giving you the correct version.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Latency Bucket Counter cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Datadog's OA.
Datadog reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Latency Bucket Counter FAQ
How hard is the Datadog Latency Bucket Counter really?+
Easy. It's a counting problem with one formula. The difficulty is purely in edge cases: the overflow bucket and numOfBuckets equal to 1. If you write the min clamp first, the rest is a basic loop over the array.
What's the trick to solve it fast?+
Compute index as latency divided by bucketWidth using integer division, then clamp with min(index, numOfBuckets - 1). Increment that slot in a zero-filled result array. One pass, no sorting needed, no nested loops.
Do I need the fact that the array is sorted?+
No. Sorted input lets you use two pointers or binary search on bucket boundaries, but a single linear pass is already O(n) and fits 10^5 elements easily. Don't overcomplicate it. Mention the sorted property if asked, then use the simple approach.
What edge cases should I test before submitting?+
Test numOfBuckets = 1 so everything goes to overflow. Test a latency exactly on a boundary, like 10 with width 10, which belongs in bucket 1. Test values far above the last boundary, like 10^9, to confirm the clamp works.
How do I prepare for this in 48 hours?+
Practice a few histogram and frequency-count problems that use integer division for indexing. Write this one from scratch twice, including the overflow clamp. Then review prefix sums and binary search in case a follow-up asks for cumulative or percentile counts.