Statistics

Problem Statement for "Chivalry"

Problem Statement

Two lines (or queues) of people often have to merge into a single-file line. But, chivalry is not dead! When a man and a woman are about to merge, the man will always let the woman go first.

Given two lines of both men and women, write a method getOrder which will determine the genders of the people in the final line. If two women are at the front of both lines, the woman from the first line goes first. Likewise, if two men are at the front of both lines, the man from the first line goes first. Then, the people at the front of both lines are compared again.

Each input line will be a String of letters, each one representing either a man or a woman. Each man will be represented by an 'M' and each woman by a 'W'. The output should be of the same form. The front of each line is the left-most character of the String.

Definition

Class:
Chivalry
Method:
getOrder
Parameters:
String, String
Returns:
String
Method signature:
String getOrder(String first, String second)
(be sure your method is public)

Constraints

  • first and second will each be between 1 and 50 characters long, inclusive.
  • first and second will consist of the characters 'M' and 'W' only.

Examples

  1. "M"

    "W"

    Returns: "WM"

  2. "MM"

    "MW"

    Returns: "MMMW"

    Because of the 'tie breaker' rules, the first man from the first line goes first. Then, the second man from the first line goes, then the rest of the people (both from the second line.)

  3. "MMMM"

    "W"

    Returns: "WMMMM"

  4. "M"

    "WWW"

    Returns: "WWWM"

  5. "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMW"

    "WMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"

    Returns: "WMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"

  6. "MMMMMWWWW"

    "MWWWW"

    Returns: "MMMMMWWWWMWWWW"

  7. "MWWWW"

    "MMMMMWWWW"

    Returns: "MWWWWMMMMMWWWW"

  8. "WMW"

    "WMW"

    Returns: "WWMWMW"

  9. "WWWW"

    "WWWW"

    Returns: "WWWWWWWW"

  10. "MMMM"

    "W"

    Returns: "WMMMM"

  11. "W"

    "MMMM"

    Returns: "WMMMM"

  12. "MMMMMMMMMMWWWWWWWWWWMMMMMMMMMMWWWWWWWWWWMMMMMMMMMM"

    "WWWWWWWWWWMMMMMMMMMMWWWWWWWWWWMMMMMMMMMMWWWWWWWWWW"

    Returns: "WWWWWWWWWWMMMMMMMMMMWWWWWWWWWWMMMMMMMMMMWWWWWWWWWWMMMMMMMMMMMMMMMMMMMMWWWWWWWWWWMMMMMMMMMMWWWWWWWWWW"

  13. "MWW"

    "WMMMMMMMWW"

    Returns: "WMWWMMMMMMMWW"

  14. "MWWWMMMMWWM"

    "MMMWWWMWMW"

    Returns: "MWWWMMMMWWMMMMWWWMWMW"

  15. "WMWMWMWM"

    "MMMMMMMMMMMMM"

    Returns: "WMWMWMWMMMMMMMMMMMMMM"

  16. "WWWMMMWWWWWWWWWMWWWWWWWWWW"

    "WMMMWMWMWMWMMMMMWWMWWMWMW"

    Returns: "WWWWMMMWWWWWWWWWMWWWWWWWWWWMMMWMWMWMWMMMMMWWMWWMWMW"

  17. "WWMM"

    "MMM"

    Returns: "WWMMMMM"

  18. "MWWWW"

    "WMMMM"

    Returns: "WMWWWWMMMM"

  19. "WWWWW"

    "WWWW"

    Returns: "WWWWWWWWW"

  20. "M"

    "W"

    Returns: "WM"

  21. "MW"

    "M"

    Returns: "MWM"

  22. "MMMMWMMWMMMMMM"

    "WWWWMMMWWWWWW"

    Returns: "WWWWMMMMWMMWMMMMMMMMMWWWWWW"

  23. "WWWWW"

    "MMM"

    Returns: "WWWWWMMM"

  24. "WMM"

    "WMM"

    Returns: "WWMMMM"

  25. "WMM"

    "WWW"

    Returns: "WWWWMM"

  26. "WMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWM"

    "WMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWM"

    Returns: "WWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWM"

  27. "MMWW"

    "MMMM"

    Returns: "MMWWMMMM"


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: