Recent Advertisement Click Counts
Problem statement
You receive a finite sequence of advertisement click and count operations. Each operation is one of:
CLICK <adId> <timestamp>: record one click for the advertisement.COUNT <adId> <timestamp>: report how many clicks that advertisement received during the latestkMinutes.
Timestamps are integer seconds and never decrease. Process operations in input order, including operations with the same timestamp. For a count at time t, include clicks whose timestamps are in the inclusive interval [t - 60 * kMinutes + 1, t].
Examples
Example 1
operations = ["CLICK shoes 100","CLICK books 120","CLICK shoes 159","COUNT shoes 160","COUNT books 180","COUNT shoes 220"]kMinutes = 1return = [1,0,0]At time 160, only the shoes click at 159 remains in [101,160]. The books click at 120 is outside [121,180], and both shoes clicks are outside [161,220].
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 1 more worked example, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.