Statistics

Problem Statement for "MakingPairs"

Problem Statement

You have a collection of cards. Each card contains an integer between 0 and N-1, inclusive.

You are given a int[] card with N elements. For each valid i, you have exactly card[i] cards that contain the integer i.

You want to create pairs of cards that have the same number. Each card can only be used at most once. Return the largest number of pairs you can create.

Definition

Class:
MakingPairs
Method:
get
Parameters:
int[]
Returns:
int
Method signature:
int get(int[] card)
(be sure your method is public)

Notes

  • The value of N is not given explicitly. You can determine its value by looking at the number of elements in card.

Constraints

  • N will be between 1 and 50, inclusive.
  • card will have exactly N elements.
  • Each element of card will be between 0 and 50, inclusive.

Examples

  1. {2,2,2}

    Returns: 3

    You have two cards with the number 0, two cards with the number 1, and two cards with the number 2. You can use these cards to form three pairs of identical cards: 0 with 0, 1 with 1, and 2 with 2.

  2. {1,1,1}

    Returns: 0

    Here, you have three cards that have the numbers 0, 1, and 2, respectively. As these cards are all distinct, you cannot make any pairs. Thus, the correct return value is 0.

  3. {5}

    Returns: 2

    You have five cards. Each of them contains the number 0. Using these cards, you can form at most two pairs of identical cards. (Note that you cannot use the same card in multiple pairs.)

  4. {43,23,10,39,39,22,22,0,3,4,3,2}

    Returns: 102

  5. {0}

    Returns: 0

  6. {26,22,43,38,19,23,4,47,1,18,29,48,44}

    Returns: 178

  7. {28,50,42,19,35,9,39,44,40,16,6,18,16,44,11,45,45,18,42,33,11,16,43,39,36,6,9,9,22,44,41,0,41,39,42}

    Returns: 491

  8. {14,19,37,26,2,20,35,31,0,1,28}

    Returns: 104

  9. {17,33,42,45,41,9,46,5,49,22,34,23,8,8,45,35,43,1,33,37,5,0,32,22,34,27}

    Returns: 340

  10. {30,48,1,38}

    Returns: 58

  11. {34,30,27,45,9,24,45,48,22,49,41,21,3,29,30,16}

    Returns: 232

  12. {25,42,35,17,38,27,48,22,2,31,0,50,24,38,16,5,8,15,33,44,23,25}

    Returns: 279

  13. {33,21,43,3,14,26,40,43,22,25,8,30,24,6,20,50,45,36,17,18}

    Returns: 258

  14. {33,22,7,7,31,20,40,19,1,40,45,24,35,46,5,44,40,35,7}

    Returns: 245

  15. {35,3,24,26,45,21,34,42,46,30,12,33,31,31,47,3,9,16,35,21,30,48,1,46,5}

    Returns: 330

  16. {8,45,39,42,7,14,11,7,43,49,45,41,5,50,34,30,23,16,30,45,34,9,44,39,18,50,36,8,39,11}

    Returns: 428

  17. {34,41,11,19,44,10,46,45,3,26,29,19,27,5,38,11,29,10,26,16,49,4,32,26,49,37,8,27,45,46,39,49}

    Returns: 441

  18. {4,8,36,9,9,14,46,15,23,35,44,30,13,19,37,29,28,10,50,40,5,12,48,1,15,46,1,15,24,20,9,29}

    Returns: 354

  19. {1,38,33,43,23,32,44,50,13,6,28,19,46,4,18,41}

    Returns: 216

  20. {0,23,45,25,14,19,45,1,30,44,16,42,46,43,38,39,25,42,30,11,15,36,41,49,5,30,18,19,46,6,40,1,28,26,17,0,33,37,7,17}

    Returns: 514

  21. {26,2,28,20,9}

    Returns: 42

  22. {40,16,18,1,44,30,13,5,41,3,4,8,19,38,2,6,8,21,12,45}

    Returns: 183

  23. {34,32,46,7,6,39,41,48,18,36,2,26,15,24,2,36,6,35,29,41,9}

    Returns: 262

  24. {16,31,46,6,19,3,47,20,6,3,19,40,1,19,31,13,21,18,41,48,0,11,0,7,21,17,27,30,38,29,0,18,22,37,12,26,0,2,12,37,9,30,35,38,49,3}

    Returns: 467

  25. {9,29,10,32,22,4,48,45,21}

    Returns: 108

  26. {8,42,47,26,37,21}

    Returns: 89

  27. {21,33,23,33,43,18,12,42,24,30,24,41,22}

    Returns: 180

  28. {37,4,11,8,42,50,18,13,48,32,37,17,40,46,36,33,17,44,38,48,7,36,23,3,49,26,2,35,43,42,42,16,25,11,31,47,35,33,38,16,12,49,28,9}

    Returns: 628

  29. {32,2,46,15,36,45,42,19,32,31,50,9,18,6,5,31,30,5,8,18,41,6,41,16,18,42,36,18,44,49,42,50,26,11,0,1,28,4,48}

    Returns: 494

  30. {36,48,8,26,23,7,23,9,14,20,45,1,31,46,45,21,17,23,28,30,21,44,30,37,37,8,2,46,20,42,30,9,27,23,14,17,30,1,36,29,49,20,15,13,31,13}

    Returns: 560

  31. {36,37,23,35,23,6,31}

    Returns: 93

  32. {32,25,3,49,31,41,36,11,12,43,44,4,31,0,28,44,22,44,12,48,26,11,22,37,43,12,16,19,13,17,4,42,14,22,22,35,14,24,16,32,32,27,8,24,7}

    Returns: 541

  33. {37,0,19,41,13,24}

    Returns: 65

  34. {8,30,0,9,14,36}

    Returns: 48

  35. {38}

    Returns: 19

  36. {24,37,22,15,47,3,15,37,31,4,9}

    Returns: 118

  37. {34,21,38,44,19,24,32,36,21,23,11,16,34,10,29,35,5,20,49,44,15,49,45,0,23,28,27,3,46,5,4,1,50,11,5,17,50,28,6,0,19,34,16,50,17,39,27,34,2}

    Returns: 586

  38. {47,0,50,26,42,45,8,13,25}

    Returns: 126

  39. {5,17,25,35,43,5,41,42,22,26,1,15,21,37,14,32,42,24,36,26,3,23,32,30,39,2,25,31,47,47,26,30,36,39,9}

    Returns: 454

  40. {22,33,44,5,29,21,9,1,10,36,25,32,14,3,37,26,22,39,6,26,34,27,4,17,27,31,17,0}

    Returns: 291

  41. {40,43,50,47,38,21,5,35,27,20,29,35,11,35,27,39,27,40,22,44,38,12,22,49,12,11,17,43,22,42,30,45,41,11,44,40,18,1,24,17,50,45,40,12}

    Returns: 649

  42. {5,38,26,28,28,37,18,15,15,28,1,17,3,24,19,9,5,5,14,10,40,3,45,21,29,22,43,39,24,13,31,16,16,36,14,35,0,38,7,9,47,16,5,8,24}

    Returns: 451

  43. {27,24,31,41,2,9,31,33,13,4,21,1,48,38,40,10,17,40,50,23,46,50,48,47,21,39,32,32,40,21,31,9,12,41,16,41,32,20,42,28,20,47,9,11,24,18,32,11,9,21}

    Returns: 664

  44. {31,3,27,45,27,5,24,28,24,50,24,27,29,42,18,19,35,18,11,22,26,36,35,35,28,36,4,47,49,28,22,4,28,10,5,14,6}

    Returns: 453

  45. {4,3,8}

    Returns: 7

  46. {17,29,29,30,39,0,17,47,6,15,28,11,32,35,3,45,43,25,43,50,0,41,46,7,20,42,19,7,26,17,3}

    Returns: 376

  47. {17,19,7,14,37,33,3,6,0,14,47,12,44,42,28,47,17,5,0,26,49,42,1,9,37,48,32,6,29,43,43,17,14,43}

    Returns: 406

  48. {26,8,47,10,31,47,32,16,10,11,1,20,34,50,22,26,5,28,42,9,15,5,47,48,45,14,34,35,4,50,8,19,6,47,18,28,23,21,33,45,12,25,13}

    Returns: 525

  49. {44,31,34,27,37,7,50,41,31,44,33,28,39}

    Returns: 219

  50. {48,17}

    Returns: 32

  51. {12,33}

    Returns: 22

  52. {17,3,49,5,50,37,28,44,31,32,31,2,10,16,41,17,34,39,50,40,34,36,40,45,19,25,44,13,49,10,40,7,17,0,41,35,28,11,1,2,8,0,18,35}

    Returns: 556

  53. {20,3,20,23,27,49,31,29,28,42,6,33,43,37,15,0,26,8,4,7,33,0,28,46,33,9,4,41,12,9,24,23,14}

    Returns: 355

  54. {16,47,20,33,38,44,48,17,47,48,47,17,20,12,48,25,16,12,36,18,49,14,41,8,8,48,30,6,12,45,14}

    Returns: 437

  55. {48,6,22,20,14,20,0,7,49,43,29,39,44,38,40,30}

    Returns: 222

  56. {43, 23, 10, 39, 39, 22, 22, 0, 3, 4, 3, 2 }

    Returns: 102

  57. {5 }

    Returns: 2

  58. {50 }

    Returns: 25

  59. {8, 8, 8 }

    Returns: 12


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: