Teemo Attacking Problem
Teemo Attacking Problem — ExecCode Easy DSA Practice
Solve the Teemo Attacking problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo attacks Ashe at second timeSeries[i], and an integer duration. Your task is to compute the required answer and return the total number of seconds that Ashe is poisoned. Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1]. If Teemo attacks again before the poison effect ends, the timer for it is reset, and the poison effect will end duration seconds after the new attack.
Examples
Input {"timeSeries": [1, 4], "duration": 2}; Output 4. Input {"timeSeries": [1, 2], "duration": 2}; Output 3
Constraints
1 <= timeSeries.length <= 10^4 0 <= timeSeries[i], duration <= 10^7 timeSeries is sorted in non-decreasing order.
Practice Teemo Attacking free on ExecCode. Browse DSA problems, topic map, and placement guides.