Description
Our hero Teemo is attacking an enemy Ashe. Teemo's attacks apply poison that lasts for a given duration. Given an array timeSeries (sorted in ascending order) representing attack times and an integer duration representing the poison duration per attack, return the total time that Ashe is poisoned. If Teemo attacks while the poison is still active, the poison timer resets to the full duration (poison effects do not stack, they refresh).
Examples
timeSeries = [1,4], duration = 24Poisoned at [1,2] and [4,5] = 4 seconds.
timeSeries = [1,2,3,4], duration = 36Attack at time 1 poisons until time 4, but new attacks at times 2, 3, and 4 refresh the poison. The poison expires at time 4+3=7, so total poisoned time is from 1 to 7 = 6 seconds.
timeSeries = [5], duration = 1010Single attack at time 5 with poison duration 10. Enemy is poisoned from time 5 to time 15, giving a total of 10 seconds of poison.
Constraints
- •
1 ≤ timeSeries.length ≤ 10^4 - •
0 ≤ timeSeries[i], duration ≤ 10^7