Ctrl K

Pair Duels Along a Chain

Easy
You get a singly linked list head of even length. Counting positions from zero, every even position holds an even number and every odd position holds an odd number. Split the list into neighbouring pairs: nodes 0 and 1, nodes 2 and 3, and so on. Within each pair the two numbers duel: - if the number at the odd position is larger, team "Odd" scores a point; - if the number at the even position is larger, team "Even" scores a point. Return the name of the team with more points, or "Tie" if the scores are equal.
Example 1
head=list_node([8, 3, 2, 9, 6, 1]) → 'Even'

The pairs are (8, 3), won by Even, (2, 9), won by Odd, and (6, 1), won by Even. Even wins 2 to 1.

Example 2
head=list_node([10, 11, 12, 5]) → 'Tie'

(10, 11) gives Odd a point and (12, 5) gives Even a point. It is 1 to 1, so the answer is Tie.

Example 3
head=list_node([2, 7]) → 'Odd'
Constraints
  • The list has between 2 and 100 nodes, and the count is even
  • 1 ≤ node value ≤ 100
  • Values at even positions are even, values at odd positions are odd
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsZip Two Sorted Chains EasyThin Out a Sorted Chain EasyCut Out Matching Nodes EasyFlip the Chain EasySymmetric Bead String Easy
loading Python…
Input
head=list_node([8, 3, 2, 9, 6, 1])
Expected
'Even'

Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.