Odd or Even Card Game Winner
Problem statement
Andrew and Maria each hold a row of cards with numbers on them. andrew[i] and maria[i] are the cards at index i, counting from 0.
The string s says which indices are played. If s is "Even", only the cards at even indices (0, 2, 4, ...) count. If s is "Odd", only the cards at odd indices (1, 3, 5, ...) count.
Add up each player's cards at the played indices. Return "Andrew" if Andrew's total is bigger, "Maria" if Maria's total is bigger, and "Tie" if the totals are equal. If no index is played, both totals are 0 and the answer is "Tie".
Function
findWinner(andrew: int[], maria: int[], s: String) → StringExamples
Example 1
andrew = [1,2,3]maria = [3,2,0]s = "Even"return = "Andrew"Use indices 0 and 2. Andrew has 1 + 3 = 4 and Maria has 3 + 0 = 3. Maria has the bigger card at index 0, but Andrew's total is bigger, so the answer is "Andrew".
Example 2
andrew = [1,2,3]maria = [3,2,0]s = "Odd"return = "Tie"Use only index 1. Both players have a 2 there, so the totals are equal and the answer is "Tie".
Example 3
andrew = [5,1,4,0]maria = [2,6,2,3]s = "Odd"return = "Maria"Use indices 1 and 3. Andrew has 1 + 0 = 1 and Maria has 6 + 3 = 9, so the answer is "Maria".
Constraints
1 <= andrew.length == maria.length <= 10^40 <= andrew[i], maria[i] <= 10^4sis either"Odd"or"Even"