Tap here to switch tabs
Problem
Submissions

Problem: Teemo Attacking

med
30 min
Try to solve the Teemo Attacking problem.

Statement

An attacking character inflicts a poison condition on a target. When an attack lands at second t, the target remains poisoned for duration seconds, covering the inclusive time interval [t,t+extduration−1][t, t + ext{duration} - 1]. If another attack lands before the previous poison effect ends, the effect timer resets and extends for duration seconds starting from the timestamp of the new attack.

You are given an integer array timeSeries sorted in nondecreasing order, where timeSeries[i] represents the second at which an attack lands, along with an integer duration.

Return the total number of seconds that the target remains poisoned.

Constraints:

  • 1≤1 \leq timeSeries.length ≤104\leq 10^4

  • 0≤0 \leq timeSeries[i], duration ≤107\leq 10^7

  • timeSeries is sorted in nondecreasing order.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Teemo Attacking

med
30 min
Try to solve the Teemo Attacking problem.

Statement

An attacking character inflicts a poison condition on a target. When an attack lands at second t, the target remains poisoned for duration seconds, covering the inclusive time interval [t,t+extduration−1][t, t + ext{duration} - 1]. If another attack lands before the previous poison effect ends, the effect timer resets and extends for duration seconds starting from the timestamp of the new attack.

You are given an integer array timeSeries sorted in nondecreasing order, where timeSeries[i] represents the second at which an attack lands, along with an integer duration.

Return the total number of seconds that the target remains poisoned.

Constraints:

  • 1≤1 \leq timeSeries.length ≤104\leq 10^4

  • 0≤0 \leq timeSeries[i], duration ≤107\leq 10^7

  • timeSeries is sorted in nondecreasing order.