There are n candidates (n >= 2), each with a given score. For every candidate, output the maximum score among all other candidates - excluding only that candidate's own position, even if another candidate elsewhere shares the same value. Print the n resulting values, space separated, in the original candidate order.
Line 1: an integer n.
Line 2: n space-separated integers, the scores.
n space-separated integers: for each position i, the maximum score among all positions other than i.
Example 1
Input
4 3 7 2 7
Expected
7 7 7 7
Explanation
Excluding index 0 (value 3): max(7,2,7)=7. Excluding index 1 (value 7): the other 7 still counts, max(3,2,7)=7. Same for the rest, so every output is 7.
Example 2
Input
3 5 1 9
Expected
9 9 5
Explanation
Excluding 5: max(1,9)=9. Excluding 1: max(5,9)=9. Excluding 9: max(5,1)=5.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →