Skip to content

Teemo Attacking

EasyIntervals
Decode it first. Clues, constraints, pattern and plan before any code.

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.

time_series = [1, 4], duration = 2  →  4   (poisoned during 1-2 and 4-5)
time_series = [1, 2], duration = 2  →  3   (poisoned during 1-3)

Constraints

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