Statistics

Problem Statement for "BallsOnAMeadow"

Problem Statement

There once was a meadow:

................

Then, somebody dropped some balls onto the meadow:

.()...()().().()

Finally, some grass grew on the meadow, obscuring some of the balls:

.(|||.()(||||||)

You are given the String meadow with the final state of the meadow. Return the smallest possible number of balls that were on the meadow.

Empty ground is the character '.', each ball is the string "()", and each blade of grass is the character '|'. It is guaranteed that the balls did not overlap. For example, the input meadow = "(()" is invalid. Formally, meadow was produced by taking a string of periods, changing some ".." into "()" and then changing some characters to '|'.

Definition

Class:
BallsOnAMeadow
Method:
count
Parameters:
String
Returns:
int
Method signature:
int count(String meadow)
(be sure your method is public)

Constraints

  • meadow will contain between 1 and 50 characters, inclusive.
  • meadow will have the form described in the problem statement.

Examples

  1. ".(|||.()(||||||)"

    Returns: 4

    The example from the problem statement. Even though in the problem statement there were five balls, the situation seen in this meadow can also be produced using only four balls.

  2. "()"

    Returns: 1

  3. "||"

    Returns: 0

  4. "(|(|(||)|)|)"

    Returns: 6

  5. ".....|||||....."

    Returns: 0

  6. "."

    Returns: 0

  7. "|"

    Returns: 0

  8. "(|"

    Returns: 1

  9. "|)"

    Returns: 1

  10. "|.|||||.||.|||||.|||.||||"

    Returns: 0

  11. "|||||||||||||||||(|(|||||(|||||||||"

    Returns: 3

  12. "||.()|||()()||.|.|)..()()||(||||.||.|||"

    Returns: 7

  13. "|)|||||||||"

    Returns: 1

  14. "|||||||||||.||||(|||||||||||||||.|||||||||||||)|||"

    Returns: 2

  15. "()|)()()|)|).().()()()()()(||)()()"

    Returns: 16

  16. "()()()()()||()||()()()(|(|"

    Returns: 11

  17. ".....(|()().."

    Returns: 3

  18. "()()()()()()()().()()()().().()()()()()()"

    Returns: 19

  19. "(|()|)()()."

    Returns: 5

  20. ".()......|)()....()"

    Returns: 4

  21. "..|.()."

    Returns: 1

  22. "............."

    Returns: 0

  23. "(|.|..()"

    Returns: 2

  24. "|).|().||)()|.(|().()()(|||.|)"

    Returns: 10

  25. "|)|)(||()|)|..|)|.....||().()||.||"

    Returns: 8

  26. "||...||||||||||||||||..||.|)"

    Returns: 1

  27. "|(||||||)|.(||).||.(|||()|"

    Returns: 6

  28. ".||()|...||||.()||)|||()().()||).()"

    Returns: 8

  29. "||||||)|)||.||(|.|||.||..||"

    Returns: 3

  30. "|.|||||.||"

    Returns: 0

  31. "...|||.|||||.."

    Returns: 0

  32. ".|).()|||||.|..(|||||..||.|(||.|)..."

    Returns: 5

  33. "...........()..|.()....."

    Returns: 2

  34. "||().()|)()||"

    Returns: 4

  35. ".().||.||)||(||)|)(||)..|.(|..(||..|.."

    Returns: 9

  36. "|.||||||||||.||"

    Returns: 0

  37. "........|.()...."

    Returns: 1

  38. "..|.()....|.......|.|||.||........|....."

    Returns: 1

  39. "|.()..().()..()()()().()"

    Returns: 8

  40. "||||.||||)||||||(|.||||||(||||||"

    Returns: 3

  41. "||.||(|||||)()|().||).()(||)||(||||(|"

    Returns: 10

  42. "......()"

    Returns: 1

  43. "|).|)...."

    Returns: 2

  44. "||||||.||||.||||||||||||||||||||||"

    Returns: 0

  45. "(||()()().|(|(|()...(|().(|."

    Returns: 10

  46. "|||||||||||||||||||||||||||)||||||||||"

    Returns: 1

  47. "|||||.|||||||||||||||."

    Returns: 0

  48. "||.|||..||||||"

    Returns: 0

  49. "()()(|(|(||)(|()|)()|)"

    Returns: 11

  50. "(|()(|(|||(||)"

    Returns: 6

  51. "||||...|....||.|.|||.|.|||||||||.|||"

    Returns: 0

  52. "|||||.|.|||.||...|||||||)|.....|.|)..|||.().|||.||"

    Returns: 3

  53. "(|(|||)|||(||||)|||)|.()(|||||||(||||||||||"

    Returns: 9

  54. "|||.||||||||||.|||||||.|||||||)()|||||||||||||||.|"

    Returns: 2

  55. "||||.|||||.||.||.||.|||||(|.||"

    Returns: 1

  56. "||().|(|..(||()|.|||"

    Returns: 4

  57. "||.||...|"

    Returns: 0

  58. ".|.|||||||"

    Returns: 0

  59. "()||(|||..().(|()()()|).||(|."

    Returns: 9

  60. "|||)||||.|(|||||||||(|||||||||||"

    Returns: 3

  61. "|..(|.|.|....||..."

    Returns: 1

  62. "|||||||||||||"

    Returns: 0

  63. "()()()|().()()()...()()()(|()()"

    Returns: 13

  64. "|||||.||||||||..||)|"

    Returns: 1

  65. "|||)|||||||||||||||||||||||||)|||||||||)(|||(|"

    Returns: 5

  66. "||||.||||||.|.|||.||.||.|||||||||||||||||||."

    Returns: 0

  67. ".()|).(|()|)|)()|)||()"

    Returns: 9

  68. "().|.||......()()(|.|.....()(|.........|....."

    Returns: 6

  69. ".|)|||||().||).|.."

    Returns: 3

  70. "|||||||||||||)|||||.||||"

    Returns: 1

  71. "(|()()(||)()()|)(|()()()(||)||||()"

    Returns: 15

  72. "|||||||)|.||||||||||...|||..|"

    Returns: 1

  73. "|............"

    Returns: 0

  74. "|||||"

    Returns: 0

  75. "||.||()|"

    Returns: 1

  76. "|||||||||||||)||||...||||||)||||||||||||||)||"

    Returns: 3

  77. "||||||||||||||||||)|||||"

    Returns: 1

  78. "..()|)....||.(||"

    Returns: 3

  79. "|)()|).|()()||."

    Returns: 5

  80. "||)||)||"

    Returns: 2

  81. "||||||."

    Returns: 0

  82. ".|||||||||||||||||||||||||...|||||||||.||||"

    Returns: 0

  83. "||||||||||||||||||(||.|||||()|(||||||)||||||"

    Returns: 4

  84. "||||()(||||)|)(|(||)(||||)()||()|).|)()(||)||)()||"

    Returns: 18

  85. "..()."

    Returns: 1

  86. "|||)|)()||(|||()||||"

    Returns: 5

  87. "|..||(||||||..||.||||...||||"

    Returns: 1

  88. "||||||||||.||||||"

    Returns: 0

  89. "()(|.().().|)()|).(|.|)..(|(|"

    Returns: 11

  90. ".||.......|....|...........|.|...|.|.|..||||..|."

    Returns: 0

  91. "..(|()()..()..|)..().()().|()|()()()"

    Returns: 12

  92. ".||||...||||(||)...|.|..|....|().|||.|()|...|.."

    Returns: 4

  93. "|||||.|||"

    Returns: 0

  94. "|)|||||..||).(|||||()(|(||||.|||.|.|)|)().()|"

    Returns: 10

  95. "()()||||||||(||||)|()()(||)(|()(|()|)()||().||)"

    Returns: 16

  96. "|||||||||||||||||||||||||||||||(||||||||||||"

    Returns: 1

  97. "().()().().(|()(|..|)||..|()"

    Returns: 9

  98. "()|.|.||.|..||..|||.()|||)....|...||(|"

    Returns: 4

  99. "()........"

    Returns: 1

  100. "()|||||(|()|)()|)||)."

    Returns: 7

  101. "....|..|....|.(|().(|...||)|(|.()|||.|.|)..."

    Returns: 7

  102. ".(|||||()|..|"

    Returns: 2

  103. "()()|().|.||||()..()....|(|(|.|||.()()"

    Returns: 9

  104. "()()()()|()()()().(|()()()()|(|(|"

    Returns: 15

  105. ".(|...........().......()......()().."

    Returns: 5

  106. "||||||||||"

    Returns: 0

  107. ".....().."

    Returns: 1

  108. "||()|).|."

    Returns: 2

  109. ".|.|.|..()|............|.|...|....|...."

    Returns: 1

  110. "()()"

    Returns: 2

  111. ".()."

    Returns: 1

  112. "|)(|"

    Returns: 2


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: