Time Limit Exceeded - python sliding window

  • 0


    I'm new to algorithm problems and can't understand why my solution would exceed the time limit?

    I think that it wouldn't even be O(n) since it only iterates over the list len(nums) / k times?

    How am I incorrect in my thinking?


    Here's the code:

    def findMaxAverage(self, nums, k):
        sums = []
        i = 0
        numslen = len(nums)
        while i + k <= numslen:
    	i += 1
        return max(sums) / k

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.