Skip to content

ORIGINAL CODING QUESTION

Notification cooldown

Deliver the first notification for each user. Deliver another only when at least cooldown time has passed since that user’s last DELIVERED notification. Ignored notifications do not restart cooldown. Return the delivered count.

Open practice workspace

Original exercise · easy. Editorial role relevance does not imply a company has asked this question.

Input and output

n cooldown, then n pairs (timestamp,userId), in nondecreasing timestamp order.

Constraints

1 ≤ n ≤ 1000; 1 ≤ cooldown ≤ 1000; times and IDs in [0,10000].

Example 1

Input

4 3 0 1 1 1 3 1 3 2

Output

3

User 1 receives at 0 and 3; user 2 at 3.

Example 2

Input

3 2 0 1 1 1 2 1

Output

2

Ignoring time 1 does not delay time 2.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

Keep a last delivery per user.

Hint 2

Ignored events must not update it.

Hint 3

A difference equal to cooldown qualifies.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →