Statistics

Problem Statement for "MagicalStringDiv1"

Problem Statement

Magical Girl Illy uses "magical strings" to cast spells. For her, a string X is magical if and only if there exists a non-negative integer k such that X is composed of k consecutive '>' characters followed by k consecutive '<' characters. Note that the empty string is also magical (for k=0).
Once Illy picked up a String S. Each character of S was either '<' or '>'. Illy can change S by removing some of its characters. (The characters she does not remove will remain in their original order.) Illy wants to change S into a magical string by removing as few of its characters as possible.
You are given the String S. Compute and return the length of the magical string Illy will obtain from S.

Definition

Class:
MagicalStringDiv1
Method:
getLongest
Parameters:
String
Returns:
int
Method signature:
int getLongest(String S)
(be sure your method is public)

Constraints

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

Examples

  1. "<><><<>"

    Returns: 4

    The longest magical string Illy can produce is ">><<". Its length is 4. To change S into ">><<", Illy must remove the characters at 0-based indices 0, 2, and 6.

  2. ">>><<<"

    Returns: 6

    S is already a magical string. Therefore Illy doesn't have to remove any character.

  3. "<<<>>>"

    Returns: 0

    Illy has to remove all characters of S.

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

    Returns: 24

  5. "<"

    Returns: 0

  6. "<<"

    Returns: 0

  7. "<>>"

    Returns: 0

  8. "<><"

    Returns: 2

  9. "><<<"

    Returns: 2

  10. "<<<>"

    Returns: 0

  11. "<<><<"

    Returns: 2

  12. "><<<<"

    Returns: 2

  13. "><><<<"

    Returns: 4

  14. "><><<>"

    Returns: 4

  15. "><<><<>"

    Returns: 4

  16. "><<>>><"

    Returns: 2

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

    Returns: 4

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

    Returns: 6

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

    Returns: 4

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

    Returns: 2

  21. ">><<>><<><"

    Returns: 6

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

    Returns: 6

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

    Returns: 18

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

    Returns: 50

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

    Returns: 8

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

    Returns: 12

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

    Returns: 0

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

    Returns: 34

  29. "><>>>><"

    Returns: 2

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

    Returns: 4

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

    Returns: 16

  32. "<>><<<>"

    Returns: 4

  33. "<<<<<>>><><<<><><<><>>><<><<><<<<>><>>><<><<><<"

    Returns: 22

  34. ">><<>>><><<<>><>>>><"

    Returns: 10

  35. "<<<><<<>><>><<>><<<>><>>><<><<>><<>><>><<<>><<<<"

    Returns: 24

  36. "><>>>>><<><<<<<<>><<<><<<<>><><><>><<<><>>>>"

    Returns: 20

  37. "><<<<>>><><"

    Returns: 4

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

    Returns: 18

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

    Returns: 8

  40. ">>><<<<"

    Returns: 6

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

    Returns: 22

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

    Returns: 10

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

    Returns: 14

  44. "<><<>"

    Returns: 2

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

    Returns: 20

  46. "<<"

    Returns: 0

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

    Returns: 22

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

    Returns: 24

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

    Returns: 18

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

    Returns: 22

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

    Returns: 24

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

    Returns: 22

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

    Returns: 20

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

    Returns: 26

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

    Returns: 20

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

    Returns: 22

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

    Returns: 24

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

    Returns: 22

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

    Returns: 26

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

    Returns: 26

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

    Returns: 30

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

    Returns: 24

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

    Returns: 6

  64. "><"

    Returns: 2

  65. ">><<<<"

    Returns: 4

  66. ">"

    Returns: 0

  67. ">>>><<<<>>><><<>><<<>><<<<<<<><<>><>>>>>><<<>>>>>>"

    Returns: 24

  68. ">><<<"

    Returns: 4

  69. "<>><<<"

    Returns: 4


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: