Leetcode 346. Moving Average from Data Stream - Python

Поділитися
Вставка
  • Опубліковано 15 гру 2024

КОМЕНТАРІ • 5

  • @adityakulkarni5577
    @adityakulkarni5577 25 днів тому

    You can do it in O(1) time O(N) space using a queue.

  • @anishsubedi6506
    @anishsubedi6506 2 роки тому +1

    Short and clear explanation!

  • @Vickydan23
    @Vickydan23 2 роки тому

    hi, please why is it -self.size

    • @anand8412
      @anand8412 2 роки тому +2

      lets say you have 7 elements in list. [10,11,12,13,14,15,16] and if you get 1-based index from reverse you get [-7,-6,-5,-4,-3,-2,-1]. so whenever you give negative index value in slicing like [-4:] it just get you all values from -4 index to end. so in this case [13,14,15,16].
      You can read how slicing works in python lists. that will give you all others operations. In general [Initial:end:indexjump].
      And if you give any negative numbers, then its just reversed 1 based index.

  • @KG_Unlimited
    @KG_Unlimited 2 роки тому +1

    Great!