Code giving wrong output


this is my code for aggressive cows problem…please help me out to figure the error

What problem are you facing ? Which test case is giving wrong output for you?

1 5 3 1 2 8 4 9 this is the test case

it should have given 3 but is givingg 1 as output