Skip to content
Decoder

Teemo Attacking

Easy

Problem

A poison attack at second t keeps the target poisoned during [t, t + duration - 1], which is duration seconds. If a new attack lands while the target is still poisoned, the timer resets: the poison now ends duration seconds after the new attack, and the old effect does not stack. time_series lists the attack times in non-decreasing order. Return the total number of seconds the target is poisoned.

Example 1

Input
time_series = [1, 4], duration = 2
Output
4
Why
poisoned during 1-2 and 4-5

Example 2

Input
time_series = [1, 2], duration = 2
Output
3
Why
poisoned during 1-3

Constraints

  • 1 <= time_series.length <= 10^4
  • 0 <= time_series[i], duration <= 10^7

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.