Easy JAVA Solution || Flawlessly Beats 84% || Easiest Approach.
IntuitionThe problem is essentially about calculating the total time during which Ashe is poisoned by Teemo's attacks. Each attack has a "poison duration", but
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem is essentially about calculating the total time during which Ashe is poisoned by Teemo's attacks. Each attack has a "poison duration", but if two attacks happen before the current poison effect ends, the poison duration is extended, not reset. So, we need to calculate how much time Ashe is poisoned, taking into account overlaps between consecutive attacks.

-   Key Points:
    -   If two attacks overlap (i.e., the next attack happens while the previous poison is still active), we only need to account for the remaining poisoned time.
    -   If there is no overlap, we simply add the full poison duration for each attack.
    -   The last attack always contributes its full duration since there’s no attack afterward.

# Approach
<!-- Describe your approach to solving the problem. -->
1.  Initialize a variable totalPoisonedSeconds to store the total poisoned time.
2.  Iterate through the timeSeries array:
    -   For each attack, check if the next attack overlaps with the current poison duration.
    -   If there’s an overlap, add the overlapping time (i.e., timeSeries[i + 1] - timeSeries[i]).
    -   If there’s no overlap, add the full duration for that attack.
3.  After the loop, add the duration of the last attack to the total  poisoned time (since it will always contribute its full duration).
4.  Return totalPoisonedSeconds.

# Complexity
- Time complexity:  O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:     O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Joke :
-   Teemo: "You should really consider slowing down with those arrows, Ashe."
-   Ashe: "Why?"
-   Teemo: "Because, you know, you’re constantly getting poisoned by your own speed. You need to slow it down to avoid the overlap!" 😜


![image.png](https://assets.leetcode.com/users/images/9463b066-66a5-4a31-ba51-56ea64a5cd5d_1738471360.8222313.png)


# Code
```java []
class Solution {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int n = timeSeries.length;
        if(n == 0) return 0;

        int totalPoisonedSeconds = 0;
        for(int i = 0; i < n - 1; i++){
            if(timeSeries[i] + duration > timeSeries[i + 1]){
                totalPoisonedSeconds += timeSeries[i + 1] - timeSeries[i];
            }
            else{
                totalPoisonedSeconds += duration;
            }
        }
        return totalPoisonedSeconds + duration;
    }
}
```
['Array', 'Simulation', 'Java']