Statistics

Problem Statement for "BallRemoval"

Problem Statement

You have N balls, where N is odd. The balls are numbered from 0 to N-1. In that order, they are arranged into a row going from the left to the right.

In addition to the number, each ball has either the word "left" or the word "right" written on it. For simplicity, we will use the character '<' instead of "left", and the character '>' instead of "right". You are given the labels on all balls as the String label. For each i, character i of label represents the word on ball i.

You will now repeat the following procedure:

  1. Choose a ball that is not at either end of the row of balls.
  2. If the chosen ball has the label '<', remove the chosen ball and also the ball immediately to the left of it. Otherwise, remove the chosen ball and also the ball to the right of it.
  3. Without reordering the remaining balls, push them together to get rid of the gap created in the previous step.
The process ends when only one ball remains in the row. That ball is called the survivor. Note that the numbers on the balls do not change during the process.

Find all possible survivors. Your method must return a String containing exactly N characters. If ball i can be the survivor, character i of the return value must be 'o' (lowercase oh). Otherwise, the corresponding character must be '.' (a period).

Definition

Class:
BallRemoval
Method:
canLeave
Parameters:
String
Returns:
String
Method signature:
String canLeave(String label)
(be sure your method is public)

Constraints

  • label will contain between 3 and 49 characters, inclusive.
  • label will contain an odd number of characters.
  • Each character of label will be either '>' or '<'.

Examples

  1. "<<>"

    Returns: "..o"

    Initially, you have three balls. Since you cannot choose balls at the ends of the row, you have to choose ball 1. As its label is '<', you remove balls 0 and 1. Hence the only possible survivor is ball 2.

  2. ">>><<"

    Returns: "o...o"

    If you choose ball 2 or ball 3 first, you have to choose ball 1 next, and the survivor will be ball 0. If you choose ball 1 first, you have to choose ball 3 next, and the survivor will be ball 4.

  3. "<<><<"

    Returns: "....o"

  4. "<><<><>"

    Returns: "o.....o"

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

    Returns: "o.....o.o.....o"

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

    Returns: "o.....o.o.........o.o"

  7. ">>>"

    Returns: "o.."

  8. "<<<"

    Returns: "..o"

  9. ">><"

    Returns: "o.."

  10. "<><"

    Returns: "o.."

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

    Returns: "o................................................"

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

    Returns: "o................................................"

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

    Returns: "................................................o"

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

    Returns: "o...............................................o"

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

    Returns: "o.o.o.o.o.o.o.o.................................."

  16. "<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"

    Returns: "................o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o"

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

    Returns: "................................................o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.."

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

    Returns: "o.o...o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o"

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

    Returns: "..o...o...o...o...o...o...o...o...o...o...o...o.o"

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

    Returns: "..o...o...o...o...o...o...o...o...o...o...o...o.o"

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

    Returns: "o.........o...o...o...o...o...o...o...o...o...o.o"

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

    Returns: "o................................................"

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

    Returns: "................................................o"

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

    Returns: "o.o.....o.....o.....o.....o.....o.....o.....o...."

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

    Returns: "....o.o.....o.o.....o.o.....o.o.....o.o.....o.o.o"

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

    Returns: "o.o.o.......o.o.......o.o.......o.o.......o.o...."

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

    Returns: "........................o.o.o.o.o.o.o.o.o.o.o.o.o"

  29. "<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>"

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o........................"

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

    Returns: "............o.o.o.o.o.o.............o.o.o.o.o.o.o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o"

  32. "<<<<<<<<<<<<<<<>>>>>>>><<<<<<<<<<<<<<>>>>>>>>>>>>"

    Returns: "o.o.o.o.o.o.o.o.........o.o.o.o.o.o.o............"

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

    Returns: "o...............o.o.o.o.o.o.o.o.................o"

  34. "<<<"

    Returns: "..o"

  35. "<>>><"

    Returns: "o...."

  36. "<>>><<<"

    Returns: "o.....o"

  37. "<<>"

    Returns: "..o"

  38. "<<><>"

    Returns: "....o"

  39. "<<<>><>"

    Returns: "o.o...o"

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

    Returns: "o.o.......o"

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

    Returns: "o...o.......o.o.o...."

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

    Returns: "o...........o.......o.........."

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.....o"

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

    Returns: "o...........o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o"

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

    Returns: "o.o.........o.o.o.o.o.o.o.o.o.o.o.o.o...o.o.o...o"

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

    Returns: "o...o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o"

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

    Returns: "o...o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o...o.o.....o...o"

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

    Returns: "o.o...o.....o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.....................o.....o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o...o"

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

    Returns: "o...o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o...o.....o"

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

    Returns: "o...o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o"

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

    Returns: "o.........o.....o.o.o.o.o.o.o.o.o.o.o.o.o.o.....o"

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

    Returns: "o.....................o...o.o...o.o.o...o.o.o.o.o"

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

    Returns: "o...............o.o.o.o.o.o.o...o.o.o.o.o.o.o.o"

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

    Returns: "o.....o.o.o...o.o.o.o...o.o.o.o.o.o.o.o.o...o"

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

    Returns: "o...........o.o.o.o.o.o.o.o.o.o...o.o.o.o.o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o...o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.......o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.o.............o"

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

    Returns: "o.o.o.o.o.o.o.o.o.o.o.o.o.o.............o"


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: