[C++] Simulation Time/Space: O(N); O(1)
\nclass Solution {\npublic:\n    int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n        int ans = 0;                           \n        vec
```\nclass Solution {\npublic:\n    int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n        int ans = 0;                           \n        vector<int> last;  // {start, end}      \n        for(auto i: timeSeries){\n            if(last.empty()) last={i, i+duration};  // case 1: 1st segment\n            else if(i <=last[1]) last[1] =  max(last[1], i+duration); // case 2: overlapping segment\n            else ans += last[1] - last[0], last={i, i+duration}; // case 3: non-overlapping segment\n        }\n        if(!last.empty())  ans += last[1] - last[0]; // if there is unprocessed.\n        return ans;\n    }\n};\n```
[]