Statistics

Problem Statement for "LeftAndRightHandedDiv2"

Problem Statement

Some students are seated in a row next to each other. Each of them is either left-handed or right-handed. You are given a String S that describes the row of students. Each character of S is either 'L' or 'R', representing a left-handed or a right-handed person, respectively. The characters describe the row from the left to the right: for all i, the person described by character i+1 sits to the right of the person described by character i.

The students are trying to write down lecture notes. Whenever a left-handed person sits immediately to the right of a right-handed person, their elbows collide when they both try to write at the same time. Compute and return the number of elbow collisions, assuming that all students in the row attempt to write at the same time.

Definition

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

Constraints

  • S will contain between 1 and 50 characters, inclusive.
  • Each character of S will be either 'L' or 'R'.

Examples

  1. "L"

    Returns: 0

    There's only one person in the row so there are no collisions.

  2. "RRR"

    Returns: 0

    Everybody is right-handed so there are no collisions.

  3. "LRLRLR"

    Returns: 2

    There will be two collisions: one of them between the second and the third person from the left (described by S[1] and S[2]) and the other between the fourth and the fifth person.

  4. "LLLRRR"

    Returns: 0

  5. "RLRLRL"

    Returns: 3

  6. "R"

    Returns: 0

  7. "LRRRRLLRRLRLRRLLLLLRLRRLLLRRRRLLLR"

    Returns: 7

  8. "RLRLRRRRLRLLRLRLRL"

    Returns: 7

  9. "RLLLRRR"

    Returns: 1

  10. "RLRLRRRLRLRLRLLRLRLLLLLRRLRLLLLRLLL"

    Returns: 11

  11. "RRLLLRRRLRLLLRLLRRRLRLRRRRRRRRRRLRRLRLRRLLRLR"

    Returns: 11

  12. "RLLL"

    Returns: 1

  13. "LRLRLRLRRRRLLLRL"

    Returns: 5

  14. "LLLLLRLRRRRRLLRRLRRLRLRRRRRLLRRLRLLRRRLLLLLL"

    Returns: 9

  15. "RRRLLRLRLRLRLLRRLLRLLLRRRLLRLLRRLLLLRLR"

    Returns: 11

  16. "RL"

    Returns: 1

  17. "RLLLLLRLLLLLRLLLLLRRLLRRRRLRL"

    Returns: 6

  18. "RRRRLRRRLLR"

    Returns: 2

  19. "LLLLLLLLRRLRLRLLLRRLLLRLRRL"

    Returns: 6

  20. "RRRRLRRLRRLRLLLLLLRLRL"

    Returns: 6

  21. "LLLLRRLRLLLRLLLLRRRLLRLLRRRLLRLLRLR"

    Returns: 8

  22. "RRLRRL"

    Returns: 2

  23. "RLLLLLRLLLRLLLLLLRLRRRLLLRL"

    Returns: 6

  24. "RLLLRRLRRRRRLLRLLRL"

    Returns: 5

  25. "RLLLRLLL"

    Returns: 2

  26. "LLLLLRRRRLLRLRRLRRRLRLRRLRRL"

    Returns: 7

  27. "RRRRLLRRRRLLRRLRLLLRRLLRLLRRRRRLRLRR"

    Returns: 8

  28. "LLLRLLRLLLLLLLLLLRLLRLRLRRRRLLLRLLL"

    Returns: 7

  29. "LRRLRRLRRLLLLLLRLLRRRRRLRRRLRR"

    Returns: 6

  30. "RRLRLRRLRLLRLLRRRRLLRRRRRLLRRRLLLLRRRRRL"

    Returns: 9

  31. "RRRRRLLLLRRLLLRRLLLLLRLLLRRRLLLRRRRLRRRLLL"

    Returns: 7

  32. "RRRLRRLRRRLRLRLRLLL"

    Returns: 6

  33. "LRLLRLRRLLRRRLRLRLLLRLRRRRRRLRRLLRLRRLLLLRRRRRRLRR"

    Returns: 12

  34. "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"

    Returns: 0

  35. "RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL"

    Returns: 25

  36. "LLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRR"

    Returns: 0

  37. "RRRLRLLRLLLLR"

    Returns: 3

  38. "LRLRLRRLRLLLLLL"

    Returns: 4

  39. "RRRL"

    Returns: 1

  40. "RRL"

    Returns: 1

  41. "RRLL"

    Returns: 1


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: