Teemo Attacking — LeetCode 495 Python Solution

EasyArraySimulation
Problem
#495
Reading time
2 min

The problem

Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds.

Example

Input
timeSeries = [1,4], duration = 2
Output
4
Explanation
Teemo's attacks on Ashe go as follows:

Python solution

Python
class Solution:
    def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
        ans = duration
        for a, b in pairwise(timeSeries):
            ans += min(duration, b - a)
        return ans

Complexity

MeasureComplexity
TimeO(n)
SpaceO(1) to O(n) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 495. Teemo Attacking?
LeetCode 495. Teemo Attacking is rated Easy on LeetCode.
What topics does LeetCode 495. Teemo Attacking cover?
LeetCode 495. Teemo Attacking is tagged Array and Simulation on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview