title: How to calculate time complexities for python functions (asymptotic notation)?
body: <pre><code>def min_avg_two_slice(A):
      if len(A) == 2: return 0
      n, idx, min_avg = len(A), None, float('inf')
      for i in range(n):
          curr = sum(A[i:i+1])
          for j in range(i+1, n):
              curr += A[j]
              avg = curr / len(A[i:j+1])
              if avg &lt; min_avg:
                  idx = i
                  min_avg = avg
      return idx
  </code></pre>
  <p>Codility has a problem under prefix sums, it's a subsequence with a minimum average slice. The solution above is brute force and was hoping for a quadratic time, however, I got O(N**3) which is cubic.</p>
  <p><strong>Assumption</strong></p>
  <ol>
  <li>The inner loop should be == O(N)</li>
  <li><code>curr = sum(A[i:i+1])</code> == O(N)</li>
  <li>The outer loop with these other two then become O(N (N + N)) == O(N (2N)) == O(N(N)) == O(N**2)</li>
  </ol>
  <p>My question is, was this assumption wrong or there's a missing complexity? Thank you.</p>