Statistics

Problem Statement for "Etiquette"

Problem Statement

Every gentleman of the nineteenth century knew the rule "Ladies first". The true gentlemen knew that there were three exceptions to this rule. One of them was that a gentleman didn't go behind a lady up the stairs.

Your task is, given a String describing people going up the stairs, return the number of people who are not true gentlemen. In more detail, the input String, read from left to right, will describe the order in which events happen on the stairs. The String will consist of characters 'L', 'G' and ' ' (space), where 'L' indicates a lady going up the stairs, 'G' indicates a gentleman going up the stairs and space (' ') characters indicate periods of time when nobody goes up the stairs (that is, the spaces divide one group of people from another). You need to count the number of "gentlemen" that allow a lady from the same group to go up the stairs before them.

Definition

Class:
Etiquette
Method:
numNonGent
Parameters:
String
Returns:
int
Method signature:
int numNonGent(String people)
(be sure your method is public)

Notes

  • Gaps between groups are assumed to be long enough. Hence, a gentleman who goes up the stairs later than a lady from a previous group doesn't necessarily count as not being a true gentleman (his status depends on his position relative the ladies in his own group).

Constraints

  • people will consist only of the characters 'L', 'G' and ' ' (space)
  • people will have between 0 and 50 characters inclusive

Examples

  1. "LGG"

    Returns: 2

  2. "GGL LGG"

    Returns: 2

  3. "GLL LL GG G GGLL"

    Returns: 0

  4. ""

    Returns: 0

  5. "LLL GGG"

    Returns: 0

  6. "LGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"

    Returns: 49

  7. "L L L L L G G G G G L L L L L G G G G G L L L L L"

    Returns: 0

  8. "LLLLLGGGGG LLLLLGGGGG LLLLLGGGGGGGGGG"

    Returns: 20

  9. "LLL LLLLLGGGGG GGGGGLLLLLGGGGGLLLLL"

    Returns: 10

  10. "GGGGGLLLLLGGGGG"

    Returns: 5

  11. "GLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGLGL"

    Returns: 24

  12. " GLL LL GG LG GGLL"

    Returns: 1

  13. "LL GG GLG GGL LG LG GL"

    Returns: 3

    The first two groups consist of people of one gender, so there is no way to check if they know rules, hence we do not count anyone here. In the third group one gentleman doesn't know the exception rule, hence we count one non-true gentleman here. In the fourth group both gentlemen are true gentlemen, so we add zero here. In the fifth the gentleman is not a true gentleman, so we add one. The sixth group is the same as the fifth group, so we add one more. In the last group the gentleman is a true gentleman, so we do not count him.

  14. "L GLGGGGGGGGGG LLGLLL L LLG G G LGG L GL G GL"

    Returns: 14

    ten random test cases

  15. "LGLG GLLG G L GGLL G L G GL GG LGL G GGLGGLGLGG"

    Returns: 9

  16. "GG GG GLG LGGLLLGLLGLLL GGGGLGG GG L GGG GLG L "

    Returns: 8

  17. "GLGLGL LG LGG L L LG G GL G LGG LGG G L G LLLG"

    Returns: 11

  18. "G GL L GL G GGLL L G G LLGGGL LGLLLGGG L GGLGL G"

    Returns: 8

  19. "G GL L GL G GGLL L G G LLGGGL LGLLLGGG L GGLGL G"

    Returns: 8

  20. "L L L LG GGGGGG LLLGLLL G LLLGLLLLLLLGLG LLG L"

    Returns: 6

  21. " GLGLLL G L LLG L L GLLLL L L L LLLGGGG G "

    Returns: 6

  22. "LGLLLLL GGGG GL GG GGLLGL GL GL GGG GLLLLL "

    Returns: 2

  23. " LLLGL L G G G LG L LLGL L G LLGGLGLL GL"

    Returns: 6

  24. "LGGGG LGGG LGGG "

    Returns: 10

  25. "GL"

    Returns: 0

  26. "LGGGGGG"

    Returns: 6

  27. "LLGLGG"

    Returns: 3

  28. "LGGGLGL"

    Returns: 4

  29. "LGLG"

    Returns: 2

  30. "LGLG LGLG LGLG LGLG LGLG LGLG LGLG LGLG LGLG LGLG "

    Returns: 20

  31. "LGLGLGLGLGLGLGLG"

    Returns: 8

  32. "LGLLLLLLL GGLLLLLL"

    Returns: 1

  33. "GLG GGLGLLLGLL LGLG LGLGLGLLGG GG LL GLG"

    Returns: 11

  34. "LGLGLGLGLG"

    Returns: 5

  35. "GLG"

    Returns: 1

  36. "LGLGLG"

    Returns: 3

  37. "LGGLG LLGLL GGLLLGG"

    Returns: 6

  38. "LLLGGGGG LGLGLG GLGLGL"

    Returns: 10

  39. "GGLLGGGGGLGGGG"

    Returns: 9

  40. "LGG GLLG GGLL"

    Returns: 3

  41. "LGL"

    Returns: 1

  42. "LGGLG"

    Returns: 3

  43. "LGLGLGG"

    Returns: 4

  44. "LGGG GLLGG LLLGGG"

    Returns: 8

  45. "LGGGG LGGG LGGG "

    Returns: 10

  46. "GL"

    Returns: 0

  47. "LGGGGGG"

    Returns: 6

  48. "LLGLGG"

    Returns: 3

  49. "LGGGLGL"

    Returns: 4

  50. "LGLG"

    Returns: 2

  51. "LGLG LGLG LGLG LGLG LGLG LGLG LGLG LGLG LGLG LGLG "

    Returns: 20

  52. "LGLGLGLGLGLGLGLG"

    Returns: 8

  53. "LGLLLLLLL GGLLLLLL"

    Returns: 1

  54. "GLG GGLGLLLGLL LGLG LGLGLGLLGG GG LL GLG"

    Returns: 11

  55. "LGLGLGLGLG"

    Returns: 5

  56. "GLG"

    Returns: 1

  57. "LGLGLG"

    Returns: 3

  58. "LGGLG LLGLL GGLLLGG"

    Returns: 6

  59. "LLLGGGGG LGLGLG GLGLGL"

    Returns: 10

  60. "GGLLGGGGGLGGGG"

    Returns: 9

  61. "LGG GLLG GGLL"

    Returns: 3

  62. "LGL"

    Returns: 1

  63. "LGGLG"

    Returns: 3

  64. "LGLGLGG"

    Returns: 4

  65. "LGGG GLLGG LLLGGG"

    Returns: 8


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: