Teemo attacking solution : O(N) CPP Solution with concept behind it.
The trick in this question is just to maintain two variables. One is to keep the total duration for which Ashe is poisoned and other is to keep track of the tim
The trick in this question is just to maintain two variables. One is to keep the total duration for which Ashe is poisoned and other is to keep track of the time upto which Ashe will be poisoned. Whenever you arrive at a time point you check if the time upto which Ashe is poisoned right now is less than or more than current time point. If less then update it to curr_timepoint + duration and increment the total duration by amount duration. Otherwise increment with suitable number(can be seen below) :).\n\n```\nclass Solution {\npublic:\n    int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n        if(timeSeries.size() == 0) return 0;\n        int time_till_infected = timeSeries[0] + duration;\n        int ans = duration;\n        for(int i = 1; i < timeSeries.size(); i++){\n            if(time_till_infected <= timeSeries[i]){\n                ans += duration;\n                time_till_infected = timeSeries[i] + duration;\n            }\n            else{\n                ans += (duration - (time_till_infected - timeSeries[i]));\n                time_till_infected = timeSeries[i] + duration;\n            }\n        }\n        return ans;\n    }\n};\n```
[]