Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1]. If Teemo attacks again before the poison effect ends, the timer for it is reset, and the poison effect will end duration seconds after the new attack.

You are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo attacks Ashe at second timeSeries[i], and an integer duration.

Return the total number of seconds that Ashe is poisoned.

&nbsp;
Example 1:

Input: timeSeries = [1,4], duration = 2
Output: 4
Explanation: Teemo's attacks on Ashe go as follows:
- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.
- At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5.
Ashe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.


Example 2:

Input: timeSeries = [1,2], duration = 2
Output: 3
Explanation: Teemo's attacks on Ashe go as follows:
- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.
- At second 2 however, Teemo attacks again and resets the poison timer. Ashe is poisoned for seconds 2 and 3.
Ashe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total.

&nbsp;
Constraints:


	1 &lt;= timeSeries.length &lt;= 104
	0 &lt;= timeSeries[i], duration &lt;= 107
	timeSeries is sorted in non-decreasing order.


class Solution:
    def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
        
        """
        timeDur = (timeSeries[0], timeSeries[0] + duration - 1)
        i = 1
        total = 0
        while i < len(timeSeries):
            if timeSeries[i] > timeDur[1]:
                total += (timeDur[1] - timeDur[0] + 1)
            else:
                total += (timeSeries[i] - timeDur[0])
            timeDur = (timeSeries[i], timeSeries[i] + duration - 1)
            i += 1
        total += (timeDur[1] - timeDur[0] + 1)
        return total
        
        """
        # Between two interval, Ashe can be poisoned only for max duration time,
        # if time differece is less than duranton, then we that value
        total = 0
        for i in range(len(timeSeries)-1):
            total += min(duration, timeSeries[i+1] - timeSeries[i])
        return total + duration
            
// Teemo Attacking
// https://leetcode.com/problems/teemo-attacking/

class Solution {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int sum = 0;
        for (int i = 0; i < timeSeries.length; i++) {
            if (i == 0) {
                sum += duration;
            } else {
                sum += Math.min(duration, timeSeries[i] - timeSeries[i - 1]);
            }
        }
        return sum;       
    }
}
class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        int ans=0;
        int n=timeSeries.size();
        for(int i=0;i<n;i++){
            ans+=min(duration,(i==n-1?duration:timeSeries[i+1]-timeSeries[i]));
        }
        return ans;
    }
};
var findPoisonedDuration = function(timeSeries, duration) {
    let totalTime=duration

    for(let i=0;i+1<timeSeries.length;i++){
        let diff=timeSeries[i+1]-timeSeries[i]
        totalTime+= diff>duration ? duration : diff
    }
    return totalTime

};
Teemo Attacking