Statistics

Problem Statement for "Highcard"

Problem Statement

Chris likes to cheat at cards. One day, his best friend challenges him to a simple game. They both take the same number of cards from a deck, shuffle them, and then play one card at a time in the order in which they were shuffled (that is, they can't sort or look at their cards). Each time they play one card, the player with the higher card gets a point. For example, if Chris picks up (in order) 2, 3, 4, and 7, and his friend picks up 3, 4, 3, and 8, then the play would be as follows:

Chris:  2 3 4 7    1 point
Friend: 3 4 3 8    3 points

However, Chris has some tricks up his sleeve. First, his friend sat down in front of a mirror, so Chris knows exactly what cards she has and in what order. Second, Chris was sneaky and took a peek at what cards he has, even though the game is supposed to be random. Finally, Chris is a master shuffler, and can order his cards in any way he wants without anyone noticing (since it's against the rules).

If they both play the same card at the same time, then no one is awarded points.

Given an int[] representing Chris's cards, and an int[] representing his friend's cards, return the maximum number of points that Chris can win.

Definition

Class:
Highcard
Method:
cheat
Parameters:
int[], int[]
Returns:
int
Method signature:
int cheat(int[] chris, int[] friend)
(be sure your method is public)

Notes

  • The deck is not a standard 52-card deck. It may only have cards 2-9, inclusive, and it may have any number of those cards.

Constraints

  • chris and friend will both contain between 4 and 50 elements, inclusive.
  • chris and friend will both contain the same number of elements.
  • each element of chris and friend will be an int between 2 and 9, inclusive.

Examples

  1. {2,3,4,7}

    {3,4,3,8}

    Returns: 2

    Chris can sort his cards to win 2 points: Chris: 4 2 7 3 2 points Friend: 3 4 3 8 2 points

  2. {2,3,4,7}

    {3,3,8,4}

    Returns: 2

    Chris can still sort his cards to win 2 points: Chris: 2 4 3 7 2 points Friend: 3 3 8 4 2 points

  3. {2,2,2,3}

    {2,2,2,3}

    Returns: 1

    Chris can sort his cards to win 1 point: Chris: 2 2 3 2 1 point Friend: 2 2 2 3 1 point

  4. {2,3,4,5,6,7,8,9}

    {2,3,4,5,6,7,8,9}

    Returns: 7

  5. {3,3,2,2,5,3}

    {3,4,2,9,8,2}

    Returns: 3

  6. {2,4,6,5,8,8,7,7,5,6,6,6,4,3,3,2,9,8,7,5,4,6,3,2,6,5,4,9,8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 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3 }

    Returns: 43

  19. { 9, 8, 7, 6, 5, 4, 3, 2 }

    { 2, 3, 4, 5, 6, 7, 8, 9 }

    Returns: 7

  20. { 9, 9, 9, 9 }

    { 2, 2, 2, 2 }

    Returns: 4

  21. { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 3, 3 }

    { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9, 3, 3 }

    Returns: 42

  22. { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }

    Returns: 50


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: