What is wrong with it?

check for this
5
1 2 3 4 5
1
5

it’s working for this. However it is not working for
5
1 2 3 4 5
1
4