FastPrepOdd or Even Card Game Winner
Problems/Odd or Even Card Game Winner

Odd or Even Card Game Winner

Indeed logoIndeed● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: In an Indeed Prime platform test, Andrew and Maria each hold a list of cards, a string s, Odd or Even, picks which indices count, and you return the winner's name or "Tie". With Andrew [1, 2, 3] and Maria [3, 2, 0], Odd gives "Tie" and Even gives "Andrew".

The report does not say how the cards are compared. In the Even example, Maria has the bigger card at index 0 and Andrew at index 2, yet Andrew wins. Adding up each player's cards fits that (4 against 3), and counting won indices does not, so here the bigger total wins. The report spells the first player both Andrew and Andrea, and once writes the second player as Mario. This version uses "Andrew", the name in the example's return value, and "Maria", the name used everywhere else. The report also gives no limits and does not say the two lists have the same length. Here both players have the same number of cards, 1 to 10^4, with values from 0 to 10^4, and when no index is played, the answer is "Tie".

The judged task matches the report at about 85%.

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) → String

Examples

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^4
  • 0 <= andrew[i], maria[i] <= 10^4
  • s is either "Odd" or "Even"

More Indeed problems

  • Insert into an Unrolled Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Course Completion OrderPHONE SCREEN · Seen May 2025
  • Recipes You Can PreparePHONE SCREEN · Seen May 2025
All Indeed interview questionsSee Indeed hiring insights
Saved
class Solution {
    public String findWinner(int[] andrew, int[] maria, String s) {
        // Write your code here.
    }
}
Checking account…