educative.io

Educative

Can you explain how the time complexity for the above algorithm is O(N*M)

The example array has 9 elements and K=5
so is the time complexity O(9 times 5) or O(5 times 5)?
Please explain.

Since in for loop the range is (len(arr)-K+1)and the max value would be 5 so time complexity would be O(5 times 5).

But it says O(KN) so (95) right? Why?

So isn’t it actually (n/2)k, and not nk?

I see that the outer loop will run n/2 times. And then for each of these outer loops, the inner loop will run 5 (k) times.

So, how do we get to n*k?