Find the greatest element

Test case passes 2/3

Your logic is incorrect

for input
4
1 2 1 3
Your output
2 -1 3 -1
Correct Output
2 3 3 -1

Correct Code