help needed in leetcode problem

Can someone help me with this [problem][1] on leetcode. My approach is to maintain maximum , second maximum , third maximum , in every window . I am getting wrong answer on two test cases . Can someone please help me . Here is my

[2] .


refer to this
It has a quite nice explanation. Comment if you don’t understand.

I’m asking what is wrong in my approach :frowning:

it is not written in the statement that all the numbers are distinct so may be there are two maximum in the current window one at the start and other somewhere in between so when you slide the window you found that a[i-k]==m so you made the maximum the second maximum but the actual maximum is somewhere in between