Statistics

Problem Statement for "ColorfulTilesEasy"

Problem Statement

Taro likes colorful things, especially colorful tiles.

Taro's room is divided into L square tiles arranged in a row. Each tile is one of the following four colors: red, green, blue or yellow. You are given a String room. If the i-th character of room is 'R', 'G', 'B' or 'Y', the color of the i-th tile is red, green, blue or yellow, respectively.

He decided to change the color of some tiles so that no two adjacent tiles have the same color. Return the minimal number of tiles he must change.

Definition

Class:
ColorfulTilesEasy
Method:
theMin
Parameters:
String
Returns:
int
Method signature:
int theMin(String room)
(be sure your method is public)

Constraints

  • room will contain between 1 and 10 characters, inclusive.
  • Each character in room will be 'R', 'G', 'B' or 'Y'.

Examples

  1. "RRRRRR"

    Returns: 3

    For example, he can change three tiles in the following way: "RRRRRR" -> "RGRGRG".

  2. "GGGGGGG"

    Returns: 3

    For example, "GGGGGGG" -> "GRGRGRG".

  3. "BBBYYYYYY"

    Returns: 4

    For example, "BBBYYYYYY" -> "BRBYRYRYR".

  4. "BRYGYBGRYR"

    Returns: 0

    The condition is already satisfied, so he doesn't need to change any tiles.

  5. "RGGBBBRYYB"

    Returns: 3

  6. "Y"

    Returns: 0

  7. "GG"

    Returns: 1

  8. "YB"

    Returns: 0

  9. "GGG"

    Returns: 1

  10. "BBG"

    Returns: 1

  11. "RYG"

    Returns: 0

  12. "RRRR"

    Returns: 2

  13. "YBBB"

    Returns: 1

  14. "RRGR"

    Returns: 1

  15. "GYGB"

    Returns: 0

  16. "BBBBB"

    Returns: 2

  17. "RRRRY"

    Returns: 2

  18. "GGRRG"

    Returns: 2

  19. "YBGBB"

    Returns: 1

  20. "BGRBG"

    Returns: 0

  21. "YYYYYY"

    Returns: 3

  22. "YGGGGG"

    Returns: 2

  23. "YYGGGY"

    Returns: 2

  24. "RRYRBB"

    Returns: 2

  25. "RYRYYB"

    Returns: 1

  26. "BRGBRG"

    Returns: 0

  27. "GGGGGGG"

    Returns: 3

  28. "RRRYYYY"

    Returns: 3

  29. "RRRRYRR"

    Returns: 3

  30. "YYRBBYY"

    Returns: 3

  31. "RGYBBGG"

    Returns: 2

  32. "RYGRGGB"

    Returns: 1

  33. "RBGRGBR"

    Returns: 0

  34. "YYYYYYYY"

    Returns: 4

  35. "GGGGGGGY"

    Returns: 3

  36. "GGGGBBBY"

    Returns: 3

  37. "RRGYYBBB"

    Returns: 3

  38. "GGYBRRBB"

    Returns: 3

  39. "RBBGGBGY"

    Returns: 2

  40. "YYRYBYBY"

    Returns: 1

  41. "BGBGBRGR"

    Returns: 0

  42. "YYYYYYYYY"

    Returns: 4

  43. "BBBBBBBGG"

    Returns: 4

  44. "BBBBBBGGR"

    Returns: 4

  45. "BRRRRYYBB"

    Returns: 4

  46. "YYYBRYYYG"

    Returns: 2

  47. "YYBBBYBGY"

    Returns: 2

  48. "GYBBYBBRY"

    Returns: 2

  49. "YBGRYRRBR"

    Returns: 1

  50. "YGBYBRBGY"

    Returns: 0

  51. "RRRRRRRRRR"

    Returns: 5

  52. "GGGGGGBBBB"

    Returns: 5

  53. "GBBBBBYYYY"

    Returns: 4

  54. "GYBBBYYYYY"

    Returns: 3

  55. "BBGBBBGRRR"

    Returns: 3

  56. "YGYYGGRGGG"

    Returns: 3

  57. "GYYYRBRGRR"

    Returns: 2

  58. "RYYYBYGRGR"

    Returns: 1

  59. "YBRYRBRGBB"

    Returns: 1

  60. "RGYBYBGBGY"

    Returns: 0

  61. "R"

    Returns: 0

  62. "RBBR"

    Returns: 1

  63. "RRRRRRRRR"

    Returns: 4

  64. "RRB"

    Returns: 1

  65. "RR"

    Returns: 1

  66. "BBGY"

    Returns: 1

  67. "RGGBBYYYY"

    Returns: 4

  68. "BRRB"

    Returns: 1

  69. "GGBBBGGGYY"

    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: