Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Find the index of elements 1 and n.
Let x be the position of 1 and y be the position of n. the answer is x + (n-y-1) if x < y and x + (n-y-1) - 1 if x > y.
Solve with full IDE support and test cases