Java O(n) time O(1)space  Clean solution. well explained
Hi there ! \n\nIdea : on each iteration we want to do the following \n1. check if at  current second timeSeries[i] is poisoned and for how long to compare it wi
Hi there ! \n\nIdea : on each iteration we want to do the following \n1. check if at  current second ```timeSeries[i]``` is poisoned and for how long to compare it with next value to\n2. indentify the actuall time Ashe was poisoned between two points ```timeSeries[i] ``` and ```timeSeries[i + 1]```\n``` if(timeSeries[i] + duration > timeSeries[i + 1])``` \nit\'s either the time difference between points ```timeSeries[i + 1] - timeSeries[i];``` example[1,2]\nor ```duration``` example [1,4];\n\n```\nclass Solution {\n    public int findPoisonedDuration(int[] timeSeries, int duration) {\n        int result = 0; //number of seconds Ashe was poisoned.\n        for(int i = 0; i < timeSeries.length - 1; i++){\n            if(timeSeries[i] + duration > timeSeries[i + 1]) // checking how long poison will last.\n                result+= timeSeries[i + 1] - timeSeries[i];  \n            else\n                result+= duration; // add duration if current time + duration is less than time when Teemo will poison Ashe again\n        } \n        return result + duration; // add last one cause its missing :) \n    }\n}\n```\nPlease upvote if you like this solution !
['Array', 'Java']