100% beats easiest O(n)
Intuitionbasically the duration of one attack is either its max duration or time taken until next attackApproachinitialize total as 0
start a for loop checking
# Intuition
basically the duration of one attack is either its max duration or time taken until next attack
# Approach
initialize total as 0
start a for loop checking consecutive pairs
set time difference as difference between next and current event
add the minimum of effect time and max duration
# Complexity
- Time complexity:
O(n)
- Space complexity:
O(1)
# Code
```cpp []
class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) 
    {
        int total =0;
        for(int i=0;i<timeSeries.size()-1;i++)
        {
            int time = timeSeries[i+1]-timeSeries[i];
            // if(time<duration)
            //     total+=time;
            // else
            //     total+=duration;
            total+=min(time,duration);
        }
        total+=duration;
        return total;
    }
};
```
['C++']