Reported September 2026
Databrickssliding window

Rolling Hit Counter

Reported by candidates from Databricks's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Databricks OA. Under 2s to a working solution.
Founder's read

The Databricks OA reported in September 2026 gives you a rolling hit counter, and the trap is an off-by-one that passes the first example and dies on the second. You process operations in order, record hits, and answer trailing-window queries. Timestamps are nondecreasing, which is the gift. It's a queue or two-pointer window problem dressed up as a design question. If you blank on the boundary, StealthCoder runs invisibly on your screen during the live OA and hands you the working version. Know the window is [t - 299, t] inclusive before you write a single line.

The problem

Process an ordered sequence of operations for a rolling hit counter. Each operation has a type and an integer timestamp:
Type 0 records one hit at that timestamp.
Type 1 queries how many recorded hits occurred during the trailing 300 seconds.
For a query at timestamp t, count hits whose timestamps are in the inclusive interval [t - 299, t]. Multiple hits at the same timestamp count separately. Operations with the same timestamp are processed in input order, so a hit is visible to a later query at that timestamp.
Return the query results in the order in which type-1 operations occur. If there are no queries, return an empty array.

Function
countRecentHits(operationTypes: int[], timestamps: int[]) → int[]

Examples
Example 1
operationTypes = [0,0,0,1,0,1]
timestamps = [1,2,3,4,300,301]
return = [3,3]
The query at time 4 counts the hits at times 1, 2, and 3. At time 301, the hit at time 1 is outside [2, 301], while the hits at times 2, 3, and 300 remain.
Example 2
operationTypes = [0,0,1,0,1]
timestamps = [1,1,1,300,301]
return = [2,1]
The first query counts both hits at time 1. At time 301, those hits lie exactly outside the window, while the hit at time 300 remains.
Example 3
operationTypes = [1,0,1]
timestamps = [100,400,400]
return = [0,1]
The first query occurs before any hit. The hit recorded at time 400 is immediately visible to the later query at the same timestamp because operations are processed in input order.

Constraints
1 <= operationTypes.length = timestamps.length <= 100000.
Every operation type is 0 or 1.
1 <= timestamps[i] <= 2147483647.
timestamps is nondecreasing.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Because timestamps never decrease, you don't need a map or a heap. Keep an array of hit timestamps and a left pointer. On a query at t, advance the pointer while hits[left] < t - 299, then return the array length minus left. Each hit is added once and skipped once, so it's O(n) total. The pitfall is the boundary. A hit at time 1 is gone at query 301 because the window is [2, 301], so the cutoff is t - 299, not t - 300. Duplicate timestamps must count separately, so don't dedupe. Also process in input order so a hit at the same timestamp is visible to a later query. Test example 2 by hand. If the boundary logic slips under pressure, StealthCoder is your hedge during the live OA, but the pointer idea is only five lines.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Rolling Hit 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as design hit counter. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Databricks's OA.

Databricks reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Rolling Hit Counter FAQ

How hard is the Databricks Rolling Hit Counter really?+

Easy to medium. The algorithm is a sliding window over a sorted list, but the inclusive [t - 299, t] boundary trips people. If you handle that and duplicate timestamps, it's a short solution. Most failures come from off-by-one, not from the idea.

What's the trick to solving it fast?+

Timestamps are nondecreasing, so store hits in an array and keep a left pointer. On each query, move the pointer past anything older than t - 299. The answer is count minus pointer. No sorting, no map, linear time overall.

Should I use a queue or a pointer over an array?+

Either works. A queue pops expired hits from the front, and an array with a left index avoids popping. Both are amortized O(1) per operation. The index approach is simpler in most languages and easy to reason about with duplicates.

What edge cases should I test before submitting?+

Test a query before any hit, which returns 0. Test several hits at the same timestamp, which count separately. Test a hit exactly at t - 299 (included) and t - 300 (excluded). Test a hit and query at the same timestamp, where the hit counts. Test no queries, which returns an empty array.

How do I prepare in 48 hours?+

Write this once from scratch with the pointer approach and run all three examples by hand. Then do one or two sliding-window problems on sorted input. Focus on writing the boundary condition correctly rather than learning new patterns.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Databricks.

OA at Databricks?
Invisible during screen share
Get it