[python, C++] Easy solution, 100% Faster O(n)
Intuition: We have to keep track of the time till the enemy is poisoned. And within that time if he is attacked again, then we need to add only the amount of ti
Intuition: We have to keep track of the time till the enemy is poisoned. And within that time if he is attacked again, then we need to add only the amount of time he is going to be poisoned extra. Confused? Take a look at this example.\n\nLets say the timeseries is [1,2,6] and poison time is 3 . And totalTime = 0 initially.\n**at time 0** : Enemy is healthy [ 0,1,2,3,4,5,6,7,8,9 . . . ]\n**at time 1**: Enemy is poisoned till time unit 3:  [ 0, **1, 2, 3,** 4 , 5, 6, 7, 8, 9 . . .]\nhence add 3 to totalTime. Therefore totalTime = 3 at t=1. And store the time till he will be poisoned in a variable. Lets say j = 3. (means, till time 3 he will be poisoned). \n\n**at time 2**: Enemy is poisoned again, but he is posioned till time 3 already, so the extra time which he is going to suffer from poison is : duration - ( abs( j - currTime ) + 1)\n                                                                  i,e = 3 - ( abs ( 3 - 2 ) + 1) =  3 - 2 = 1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  Which means that, for a extra time of 1 unit he will be poisoned again. Hence Enemy state will be  [ 0, **1, 2, 3, 4** , 5, 6, 7, 8, 9 . . .].\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  so totalTime += duration - ( abs( j - currTime ) + 1)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t       totalTime+=1 and j +=1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t hence  totalTime = 4 and j = 4\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \n**at time 6**: Enemy is already free from poison at this moment (bcz j = 4) . Hence, poisoning him now can be directly added to the totalTime with full duration. [ 0, **1, 2, 3, 4** , 5, **6, 7, 8,** 9 . . .].\ntotalTime += duration hence totalTime = 4+3 = 7\n\n complexity: **O(n)**\n\t\n\t\nPython\n```\ndef findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:\n        j, res = -1,0\n        for c in timeSeries:\n            if c <= j :\n                tmp = duration - ( abs(j-c) + 1)\n                res+= tmp\n                j+= tmp\n            else:\n                res+= duration\n                j =  c + duration - 1\n        return res\n```\n\nC++\n```\nint findPoisonedDuration(vector<int>& timeSeries, int duration) {\n        int j = -1;\n        int res = 0;\n        for(int c: timeSeries){\n            if(c <= j){\n                int tmp = duration - ( abs(j - c) + 1);\n                res+= tmp;\n                j+= tmp;\n            }else{\n                res+=duration;\n                j = c + duration -1;\n            }\n        }\n        return res;\n    }\n```
['C', 'C++', 'Python3']