In a relay, runners are chained head to tail and pass a baton down the line. Given the chain of n runner numbers (n >= 1), find the value at the middle node. If the chain has an even number of nodes, the middle is the second of the two central nodes (equivalently, the node at 0-indexed position floor(n/2)).
Line 1: an integer n.
Line 2: n space-separated integers, the node values from head to tail.
A single integer: the value at the middle node.
Example 1
Input
5 10 20 30 40 50
Expected
30
Explanation
With 5 nodes the middle (0-indexed position 2) holds 30.
Example 2
Input
4 10 20 30 40
Expected
30
Explanation
With 4 nodes the two central nodes are 20 and 30; the second middle is 30 (position 2).
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 →