Statistics

Problem Statement for "PingPongQueue"

Problem Statement

This task is about a group of people who like to play ping pong. All games of ping pong mentioned in this task are one-on-one games.
You are given a int[] skills. Each element of skills is the skill level of one person in the group. The skill levels are all distinct. Whenever two people play a game of ping pong, the one with the higher skill level always wins.
All people in the group would like to play but they only have a single table. Therefore, only two people can play at any given time.
There will be a sequence of games, numbered starting from 1. Game 1 will be played by the players who correspond to skills[0] and skills[1]. All the remaining people will form a queue, in the order in which they are given in skills. After each game the following things will happen, in order:
  1. The person who lost the game leaves the table and goes to the end of the queue.
  2. If the person who won the game has already won N games in a row, they also leave the table and they go to the end of the queue (behind the person who lost the last game).
  3. While there are fewer than two people at the table, the first person in the queue leaves the queue and goes to the table.
  4. The two people at the table play the next game.
You are given the int[] skills, the int N, and an int K. Return the two-element int[] { L, W }, where L and W are the skills of the loser and the winner of game K, in this order.

Definition

Class:
PingPongQueue
Method:
whoPlaysNext
Parameters:
int[], int, int
Returns:
int[]
Method signature:
int[] whoPlaysNext(int[] skills, int N, int K)
(be sure your method is public)

Constraints

  • skills will contain between 2 and 50 elements, inclusive.
  • Each element of skills will be between 1 and 50, inclusive.
  • All elements of skills will be distinct.
  • N will be between 1 and 100, inclusive.
  • K will be between 1 and 1000, inclusive.

Examples

  1. {1, 2, 3}

    2

    2

    Returns: {2, 3 }

    In all annotations, we call people by their skill. For example, "player 7" means "the player whose skill level is 7". In this example players 1 and 2 play the first game, and player 2 wins. For the second game, player 3 joins player 2, so we return { 2, 3 }.

  2. {1, 2, 3}

    2

    4

    Returns: {1, 2 }

    The sequence of games is as follows: Player 1 loses to player 2. Player 2 loses to player 3. Player 1 loses to player 3. After this player 1 joins the queue, player 3 also steps down because he just won 2 games in a row and joins the queue. Player 1 loses to player 2.

  3. {50, 1}

    1

    1

    Returns: {1, 50 }

  4. {8, 12}

    1

    1000

    Returns: {8, 12 }

  5. {31, 29}

    100

    1

    Returns: {29, 31 }

  6. {48, 20, 36, 7, 19}

    4

    1

    Returns: {20, 48 }

  7. {25, 49, 17, 36}

    1

    2

    Returns: {17, 36 }

  8. {25, 46, 13, 7, 2, 31, 22, 39, 45, 5}

    1

    7

    Returns: {7, 13 }

  9. {35, 37, 19, 5, 42, 4, 24, 41, 48, 28}

    1

    998

    Returns: {4, 42 }

  10. {16, 37, 41, 1, 2, 21, 50, 27, 46}

    1

    5

    Returns: {16, 46 }

  11. {17, 37, 14, 2, 47, 30, 42, 11, 41}

    1

    10

    Returns: {2, 41 }

  12. {11, 29, 19, 6, 41, 5, 26, 14, 25, 28, 32, 31, 49, 39, 18, 42, 40, 37, 9}

    1

    123

    Returns: {19, 41 }

  13. {41, 4, 29, 27, 14, 47, 44, 17, 19, 13, 35, 5, 25, 30, 34, 9, 40, 38, 49}

    1

    996

    Returns: {5, 35 }

  14. {40, 44, 17, 30, 43, 4, 34, 49, 47, 45, 25, 41, 8, 2, 50}

    8

    21

    Returns: {44, 50 }

  15. {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 30, 29, 28, 27, 26, 25, 24, 23, 22, 40, 39, 38, 37, 36, 35, 34, 33, 32, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41}

    10

    46

    Returns: {41, 50 }

  16. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50}

    3

    51

    Returns: {2, 50 }

  17. {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41}

    10

    50

    Returns: {6, 8 }

  18. {5, 29, 12, 16, 25, 36, 18, 37, 27, 49, 34, 40, 20, 3, 48, 50, 26, 19, 33, 41, 6, 22, 8, 13, 15, 43, 28, 7, 46, 45, 31, 39, 14, 38, 4, 17, 30, 44, 10, 23, 9, 24, 21, 35, 2, 11, 32, 1, 47, 42}

    3

    192

    Returns: {2, 46 }

  19. {49, 24, 26, 12, 5, 33, 25, 30, 35, 41, 46, 23, 21, 3, 38, 43, 11, 19, 34, 29, 20, 32, 39, 7, 50}

    10

    399

    Returns: {12, 50 }

  20. {27, 1, 33, 10, 50, 4, 3, 40, 32, 15, 42, 22, 26, 5, 12, 6}

    100

    1000

    Returns: {10, 50 }

  21. {43, 47, 30, 49, 19, 16, 37, 44, 35, 29, 18, 34, 21, 45, 28, 23, 38, 25, 31, 48, 24, 39, 13, 11, 20}

    7

    753

    Returns: {31, 47 }

  22. {19, 4, 48, 35, 16, 30, 27, 7, 12, 14, 49}

    14

    10

    Returns: {48, 49 }

  23. {6, 35, 42, 26, 20, 21, 28, 13, 4, 36, 2, 40, 24, 47, 38, 22, 19, 50, 16, 23, 25, 14, 37, 1}

    68

    733

    Returns: {21, 47 }

  24. {31, 45, 16, 21, 47, 18, 30, 38, 24, 14, 25, 50, 39, 19, 4, 26, 37, 43, 15, 5, 49, 9, 44, 1}

    37

    581

    Returns: {26, 39 }

  25. {46, 25, 31, 29, 34, 3, 4, 11, 13, 7, 50, 19, 6, 37, 23, 17, 5, 28, 30, 38, 24, 15, 49, 16, 36, 12, 8, 44, 48, 33, 41, 27, 2, 21, 10, 39, 45, 43, 47, 26, 1, 18, 40, 22, 20, 42, 9}

    65

    657

    Returns: {37, 49 }

  26. {10, 20, 31, 6, 5, 4, 24, 50, 15, 13, 28, 14, 1, 47, 11, 35}

    18

    123

    Returns: {20, 24 }

  27. {48, 9, 2, 12, 16, 26, 44, 38, 23, 43, 34, 3, 24, 35, 28, 21, 47, 5, 14, 30, 22, 45, 8, 39, 4, 37, 49, 20}

    38

    242

    Returns: {2, 49 }

  28. {38, 43, 36, 32, 42}

    72

    459

    Returns: {42, 43 }

  29. {14, 26, 36, 25, 34, 10, 27, 33, 15, 48, 3, 20, 46, 44, 31, 9, 35, 47, 37, 49, 29, 30, 12, 16, 42, 39, 17, 7, 28, 43, 18, 21, 23, 4}

    83

    418

    Returns: {39, 49 }

  30. {1, 45, 26, 40, 11, 28, 25, 5, 29, 7, 43, 47, 10, 8, 6, 24, 46, 3, 12, 50, 48, 35, 2, 4, 17, 36, 22, 44, 38, 20, 41, 37}

    5

    805

    Returns: {40, 48 }

  31. {23, 8, 47, 31, 26, 4, 30, 24, 10, 38, 20, 33, 2, 35, 1, 46, 39, 6, 44, 14, 22, 43, 3, 32, 45, 9, 15, 7, 12, 42, 48, 17, 11, 21, 40, 41}

    71

    961

    Returns: {9, 35 }

  32. {10, 33, 16, 9, 15, 45, 34, 13, 48}

    38

    236

    Returns: {10, 48 }

  33. {22, 28, 47, 7, 42, 2, 32, 34, 16, 37, 20, 1, 3, 13, 50, 43, 23, 4, 10, 48, 5, 14, 24, 36, 6, 9, 17, 39, 27, 46, 21, 33, 25, 29, 12, 38, 45, 40, 44, 30}

    8

    936

    Returns: {30, 46 }

  34. {48, 13, 33, 46, 41, 26, 34, 20, 12, 11, 7, 40, 43, 10}

    64

    628

    Returns: {40, 48 }

  35. {3, 48, 30, 2, 34, 19, 28, 16, 1, 37, 27, 15, 6, 11, 39, 50, 31, 14, 33, 29, 20, 13, 4, 23, 47, 18, 10, 9, 40, 45, 8, 32, 12, 42, 35, 7, 46, 41, 22, 24}

    80

    874

    Returns: {45, 50 }

  36. {50, 15, 8, 40, 11, 36, 19, 33, 23, 35, 30, 47, 9, 49, 32, 4, 6, 18, 39, 29, 7, 28, 38, 12, 10, 48, 21, 34, 22, 31, 42, 2, 27, 25, 37, 3, 46, 41, 44, 20, 1, 43, 45, 24, 14, 17, 16}

    40

    638

    Returns: {23, 49 }

  37. {47, 37, 10, 9, 7, 38, 36, 40, 48, 21, 15, 30, 8, 6, 22, 44, 34, 49, 31, 4, 42, 24, 5, 35, 18, 41, 50}

    3

    613

    Returns: {30, 42 }

  38. {33, 6, 17, 24, 31, 2}

    92

    922

    Returns: {17, 33 }

  39. {20, 2, 40, 37, 30, 18, 44, 17, 23, 25, 12, 34, 33, 27, 16, 35, 38, 8, 21, 7, 4, 11, 41, 10, 49, 46, 43, 14, 29, 42, 32, 24, 28, 13, 3, 48, 39, 22, 31, 19, 9}

    83

    684

    Returns: {25, 49 }

  40. {11, 17, 9, 3, 35, 30, 36, 25, 19, 44, 43, 7, 20, 48, 5, 23, 2, 31, 33, 39, 18, 40, 13}

    20

    222

    Returns: {7, 48 }

  41. {46, 17, 21, 16, 45, 6, 4, 24, 22, 10, 20, 19, 42, 32, 37, 30, 2, 1, 39, 36, 35, 28, 47, 3, 25, 43, 31, 38, 34, 18, 7, 13, 33}

    94

    544

    Returns: {45, 47 }

  42. {9, 20, 35, 6, 25, 2, 49, 3, 1, 5, 48, 36}

    93

    747

    Returns: {2, 49 }

  43. {5, 24, 3, 50, 40, 7, 39, 6, 10, 23, 18, 12, 43, 33, 1, 32}

    94

    515

    Returns: {10, 50 }

  44. {46, 7, 19, 27, 45, 3, 38, 49, 9, 35, 5, 6, 12, 17, 4, 28, 42, 31, 16, 33, 43, 24, 39, 10, 40, 22, 50}

    22

    220

    Returns: {33, 50 }

  45. {16, 30, 33, 10, 50, 15, 36, 11, 47, 29, 23, 26, 45, 32, 49, 22, 2, 9, 18, 38, 39, 41, 46, 43, 5, 17, 28}

    66

    201

    Returns: {39, 50 }

  46. {13, 31, 33, 46, 11, 49, 10, 40, 30, 26, 43, 48, 19, 50, 29, 42, 36, 2, 35, 24, 28, 23, 9, 27}

    75

    973

    Returns: {2, 48 }

  47. {11, 39, 16, 44, 35, 14, 21, 38, 43, 27, 25, 23, 12, 28}

    76

    437

    Returns: {12, 43 }

  48. {24, 46, 45, 25, 33, 41, 32, 9, 35, 30, 14, 4, 11, 16, 18, 28, 10, 6, 7, 29, 37, 13, 5, 48, 22, 19, 23, 50}

    64

    627

    Returns: {11, 50 }

  49. {12, 21, 48, 7, 35, 16, 36, 42, 3, 26, 22, 29, 8, 14, 44, 13, 40, 4, 31, 34, 32, 10, 28, 2, 25, 1, 49, 24, 47, 39}

    1

    661

    Returns: {12, 21 }

  50. {11, 27, 20, 16, 38, 7, 4, 37, 47, 33, 45, 24, 28, 42, 36, 12, 10}

    7

    964

    Returns: {33, 42 }

  51. {36, 44, 22, 27, 21, 35, 11, 31, 13, 9, 37, 19, 8, 1, 42, 3, 4, 10, 33, 5, 50, 46, 48, 12, 23, 28, 49, 17, 7}

    55

    397

    Returns: {9, 50 }

  52. {30, 12}

    34

    80

    Returns: {12, 30 }

  53. {1, 2, 3 }

    2

    1000

    Returns: {1, 2 }

  54. {49, 24, 26, 12, 5, 33, 25, 30, 35, 41, 46, 23, 21, 3, 38, 43, 11, 19, 34, 29, 20, 32, 39, 7, 50 }

    10

    1

    Returns: {24, 49 }

  55. {1, 2, 3, 4 }

    1

    2

    Returns: {3, 4 }

  56. {1, 2, 3 }

    2

    7

    Returns: {1, 2 }

  57. {5, 4, 3 }

    1

    2

    Returns: {3, 4 }

  58. {49, 24, 26, 12, 5, 33, 25, 30, 35, 41, 46, 23, 21, 3, 38, 43, 11, 19, 34, 29, 20, 32, 39, 7, 50 }

    1

    399

    Returns: {5, 29 }

  59. {1, 2, 3 }

    1

    2

    Returns: {1, 3 }

  60. {5, 29, 12, 16, 25, 36, 18, 37, 27, 49, 34, 40, 20, 3, 48, 50, 26, 19, 33, 41, 6, 22, 8, 13, 15, 43, 28, 7, 46, 45, 31, 39, 14, 38, 4, 17, 30, 44, 10, 23, 9, 24, 21, 35, 2, 11, 32, 1, 47, 42 }

    1

    1000

    Returns: {42, 47 }

  61. {1, 2 }

    1

    1

    Returns: {1, 2 }

  62. {1, 2, 3, 4, 5, 6 }

    1

    3

    Returns: {5, 6 }

  63. {2, 1 }

    1

    1

    Returns: {1, 2 }

  64. {5, 4, 3, 2, 1 }

    1

    2

    Returns: {2, 3 }

  65. {3, 2, 1 }

    2

    5

    Returns: {1, 3 }

  66. {10, 5, 6 }

    2

    5

    Returns: {5, 10 }

  67. {4, 5, 3, 2, 1 }

    1

    2

    Returns: {2, 3 }

  68. {49, 24, 26, 12, 5, 33, 25, 30, 35, 41, 46, 23, 21, 3, 38, 43, 11, 19, 34, 29, 20, 32, 39, 7, 50 }

    10

    399

    Returns: {12, 50 }

  69. {49, 24, 26, 12, 5, 33, 25, 30, 35, 41, 46, 23, 21, 3, 38, 43, 11, 19, 34, 29, 20, 32, 39, 7, 50 }

    3

    1000

    Returns: {7, 43 }

  70. {30, 12 }

    34

    80

    Returns: {12, 30 }


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: