Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Teemo Attacking

XPChallenge Points: 10
levelLevel: Easy

Teemo is attacking an enemy with poison attacks.
• Each time Teemo attacks at time t, the enemy becomes poisoned for the next duration seconds (inclusive), meaning the poison lasts from t to t + duration - 1.
• If another attack happens before the previous poison ends, the poison timer resets, and the new effect continues for another full duration seconds from that new attack time.
You are given:
• A non-decreasing integer array attackTimes, where attackTimes[i] represents the second of each attack.
• An integer duration, representing how long each poison effect lasts.
Return the total number of seconds the enemy remains poisoned.

Example 1:

Input: attackTimes = [2, 6] duration = 3

Output: 6

Example 2:

Input: attackTimes = [1, 3] duration = 3

Output: 5

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result