educative.io

Why is time complexity O(n * k) for the brute force solution, shouldn't it be less?

Since we are not iterating n times just (n - k + 1) times so it should really be: (n - k +1) * k = kn -k^2 + k ?

nvm figured it out

I had the same question when I looked at it. Can you clarify why it’s O(n*k) and not O((n-k)*k)?