Maximum Element problem

If the first element in the array is largest then the output is wrong.
9
4 2 3 3 5 4 5 4 5
3

Considering this as input, if we just solve for first k elements then the output comes as:
4 4 4 4 3 (output for first k elements)

It should have been 4 3…i dont know why these extra 4s are there.Please explain this test case

the correct output for this ll be
4 3 5 5 5 5 5
your logic is correct .but

first k elements means keep sliding the window .
0-2: 4
1-3: 3
2-4: 5
and so on …

if this solves your doubt please mark it as resolved :slight_smile: