Statistics

Problem Statement for "DiamondHunt"

Problem Statement

You are a diamond hunter looking for diamonds in a peculiar mine. This mine is a String of '<' and '>' characters, and each diamond is a substring of the form "<>". Each time you find a diamond, you remove it and the residual mine is updated by removing the 2 characters from the String.

For example, if you have a mine like "><<><>>><", you can start by removing the first appearance of "<>" to get "><<>>><", then remove the only remaining diamond to get "><>><". Note that this produces a new diamond which you can remove to get ">><". Since there are no diamonds left, your expedition is done.

Given a String mine, return the number of diamonds that can be found. Note that the order in which you remove simultaneous appearances of diamonds is irrelevant; any order will lead to the same result.

Definition

Class:
DiamondHunt
Method:
countDiamonds
Parameters:
String
Returns:
int
Method signature:
int countDiamonds(String mine)
(be sure your method is public)

Constraints

  • mine will contain between 1 and 50 characters, inclusive.
  • Each character of mine will be either '<' or '>'.

Examples

  1. "><<><>>><"

    Returns: 3

    The example from the problem statement.

  2. ">>>><<"

    Returns: 0

    No diamonds here.

  3. "<<<<<<<<<>>>>>>>>>"

    Returns: 9

  4. "><<><><<>>>><<>><<><<>><<<>>>>>><<<"

    Returns: 14

  5. "<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>"

    Returns: 25

  6. "><<><<><><<<<<>><<><><><>>><<>>><<><><<><><>>><<<<"

    Returns: 21

  7. ">><><><>>><><><<<><><<<>><<>><>>>><><>"

    Returns: 17

  8. "><>>>><<<><>>><<<"

    Returns: 5

  9. "<<<<<<><<>><><>>><>><>>><<>>><<>><><<><>>>>>>>>><"

    Returns: 20

  10. "><<><>>><>><<><<><<>><><<>>>><><>><>>>>>>"

    Returns: 16

  11. "><<<<<><<<<><<<<><><>>><<><<<>><>><"

    Returns: 12

  12. "<<<<<<<<<<>><><<<>><<>><><>>><<><<>>>>>><>>><<<>>>"

    Returns: 24

  13. ">>><<>>><><><><"

    Returns: 5

  14. "<><>><><><>><><><><><>>"

    Returns: 10

  15. "<><>>><>>><>><><<>><>><<>>><<<<<>><><<><><<<><><<"

    Returns: 17

  16. "<<<><><"

    Returns: 2

  17. "<>>><><<<<<<<>><><<>"

    Returns: 6

  18. "<<<>>>>>><<<<>><<<>><<<<><><><><>>><<><>><<>>>>><<"

    Returns: 22

  19. "<<<<<>><><><<<>>>><<<<><><><<>>><<>><<>><>>><><>>>"

    Returns: 25

  20. "<<<<<><><>><><<><><<<>>>>><>>>"

    Returns: 15

  21. "<><><>"

    Returns: 3

  22. "<<<<<<><><><><>>><><<>><<<<<><>>><<>>><<<><>>>>>>>"

    Returns: 25

  23. "<<<><><<<><>><><>>><>>"

    Returns: 11

  24. "<<<<<>>><<<<<>>>>><>>>"

    Returns: 11

  25. "<><><<<<><<><>>>>><><<<>>><><><<<<<><><>><<>><>>>>"

    Returns: 25

  26. "<<<<><>>>>"

    Returns: 5

  27. "<<><><<><>>>"

    Returns: 6

  28. "<<<<<>><><><><><>><><><<<><><><<>>>><><<><<>><>>>>"

    Returns: 25

  29. "<><<>>"

    Returns: 3

  30. "<<<>>><<<<<><><><>>>><><><>><<>><><><<<<<><>>>>>"

    Returns: 24

  31. "<<<<<<<<<<>><>>>>>><<><>><><<>><>><><><><<><><>>>>"

    Returns: 25

  32. "<"

    Returns: 0

  33. ">"

    Returns: 0

  34. "><"

    Returns: 0

  35. "<<"

    Returns: 0

  36. ">>"

    Returns: 0

  37. "<>"

    Returns: 1

  38. ">>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<"

    Returns: 0

  39. ">>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<"

    Returns: 0

  40. ">>>>>>>>>>>>><<<<<<"

    Returns: 0

  41. ">>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"

    Returns: 0

  42. ">>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"

    Returns: 0

  43. "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>"

    Returns: 4

  44. "<<<>>>>>>>>>>>>>>>>>"

    Returns: 3

  45. "<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>"

    Returns: 15

  46. "<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>"

    Returns: 20

  47. "<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>"

    Returns: 8

  48. "<<<<<<<<<><><>>>>>>>><<<>>>><<<<<<<>>><<>><<>>>>>>"

    Returns: 25

  49. "<<<<<<<<<<>><<>>>>>>><<>>>>>"

    Returns: 14

  50. "<<<<<<<<<>>>>>>><<>>>><><<<><>>><><<<>>>"

    Returns: 20

  51. "<><<<<<<<<<>><>><<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>><>"

    Returns: 25

  52. "<<<<<><<><>><<<>>>><><<<<><><>>>>>>>"

    Returns: 18

  53. "<><<<><><>><<<>>>>"

    Returns: 9

  54. "<<<<<<>>><><>>>><<><<<<<<<<><><<<<>>>>>>>>>><<>>>>"

    Returns: 25

  55. "<><><><><><><><><><><><><><><><<><>><><><><<>><><>"

    Returns: 25

  56. "<<><><><>><><><><<>>"

    Returns: 10

  57. "<><><><><<>><>"

    Returns: 7

  58. "<<><><<>><<><<<>>>><<>><><<<>>><>><<>><<>><><><><>"

    Returns: 25

  59. "<<><><><>><>"

    Returns: 6

  60. "<<><><><><><><><>><<>><><><>"

    Returns: 14

  61. "<><><><><><<><><<>><><><><><<>><><<><><>><><><><>>"

    Returns: 25

  62. "<><><><><><><><><><><><><><><><><><><><><><><><><>"

    Returns: 25

  63. "<><><><><><><><><><><><><><><><><><>"

    Returns: 18

  64. "<><><><><><><><><><><><><><><><><><><><><><><>"

    Returns: 23

  65. "<<<<>>>>"

    Returns: 4

  66. "<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>"

    Returns: 23

  67. ">><<"

    Returns: 0

  68. "<<>"

    Returns: 1

  69. "<<>>"

    Returns: 2

  70. "<<<<>>>"

    Returns: 3

  71. "<>>"

    Returns: 1

  72. "<<>><<>>"

    Returns: 4

  73. "<>>>>>>"

    Returns: 1

  74. ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"

    Returns: 0


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: