Getting error in this question

I am doing this question on leetcode…
1566. Detect Pattern of Length M Repeated K or More Times
For my knowledge i have implemeted in correct way…
But this is showing error for input…
arr = [2,2,2,2], m = 2, k = 3
This is my code.


Please tell me where it is getting wrong…
i am not able to find it… as i am not able to understand the error it is showing.

Hi @ashishnnnnn avoid getting out of bounds

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.