Skip to content

Practice Teemo Attacking

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#495
LeetCode Problem

Teemo Attacking

Problem Statement

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. 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. Return the total number of seconds that Ashe is poisoned.

Source: Teemo Attacking on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
timeSeries = [1,4], duration = 2
Output
4

# Example 2

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.

Related LeetCode Problems

Practice more problems similar to Teemo Attacking.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.