Teemo is attacking an enemy with poison attacks.
• Each time Teemo attacks at time t, the enemy becomes poisoned for the next duration seconds (inclusive), meaning the poison lasts from t to t + duration - 1.
• If another attack happens before the previous poison ends, the poison timer resets, and the new effect continues for another full duration seconds from that new attack time.
You are given:
• A non-decreasing integer array attackTimes, where attackTimes[i] represents the second of each attack.
• An integer duration, representing how long each poison effect lasts.
Return the total number of seconds the enemy remains poisoned.
Input: attackTimes = [2, 6] duration = 3
Output: 6
Input: attackTimes = [1, 3] duration = 3
Output: 5
Accepted:
Submission: