Statistics

Problem Statement for "WinningRecord"

Problem Statement

If a baseball team loses 15 games in a row, and then wins its next 5, there are a number of ways this could be reported. A fan of the team could brag that they have won all 5 of their last 5 games. However, it could also be truthfully said that they have won 5 out of their last 10 games, or only 25% of their last 20 games.

Given a String results with the results of the last several games a team has played, determine how many of their most recent games to consider to find the team's worst and best percentages of winning. Return a int[] with 2 elements. The first element should be how many of the team's most recent games to consider to give their best winning record (5, in the above example). The second element should be how many of the team's most recent games to consider to give their worst winning record (20, in the above example).

The String results will contain only the characters 'W' and 'L', where 'W' indicates a win, and 'L' indicates a loss. The left-most character represents the most recent game, and the right-most character represents the least recent game. The string for the example above would be "WWWWWLLLLLLLLLLLLLLL".

Never consider fewer than 3 games. When considering 7 games (for example), they must be the 7 most recent games, not any 7 from the list. If different numbers of games give the same winning record, choose the larger number of games.

Definition

Class:
WinningRecord
Method:
getBestAndWorst
Parameters:
String
Returns:
int[]
Method signature:
int[] getBestAndWorst(String games)
(be sure your method is public)

Constraints

  • results will contain between 3 and 50 characters, inclusive.
  • Each character of results will be either 'W' or 'L'.

Examples

  1. "WWWWWLLLLLLLLLLLLLLL"

    Returns: { 5, 20 }

    This is the example from the problem statement.

  2. "WWWWWW"

    Returns: { 6, 6 }

    No matter how many games you consider, the team's winning record is 100% and the losing record is 0%.

  3. "LWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLW"

    Returns: { 50, 3 }

  4. "WLWLWLLWWLWLWWWWWWWLWLLLLLLLLLLLLWWLWLLWWWLLLWLWLW"

    Returns: { 19, 33 }

  5. "LWWLWWLWWLLLW"

    Returns: { 9, 12 }

  6. "WWW"

    Returns: { 3, 3 }

  7. "LLL"

    Returns: { 3, 3 }

  8. "WLW"

    Returns: { 3, 3 }

  9. "LWL"

    Returns: { 3, 3 }

  10. "WWWL"

    Returns: { 3, 4 }

  11. "LLLW"

    Returns: { 4, 3 }

  12. "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW"

    Returns: { 50, 50 }

  13. "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"

    Returns: { 50, 50 }

  14. "WWWWWWLWWWWWWLWWWWWWLWWWWWWLWWWWWWLWWWWWWLWWWWWWLW"

    Returns: { 6, 49 }

  15. "WLWLLWLLLWLLLLWLLLLLWLLLLLLWLLLLLLLWLLLLLLLLWLLLL"

    Returns: { 3, 44 }

  16. "LWWLWWWLWWLLWWLWLWLWLLWLLLLWWLWLWWLLLWWLWLWLLWLWLW"

    Returns: { 7, 27 }

  17. "LWLLLWLWLLLWWLWLWLWLWLLWLLLLLWWWLWWLLLWLLWLLWWLLWW"

    Returns: { 35, 5 }

  18. "WLWWLLLWWWWLWWLLWWWLLWLWLWWWWWWLLLLWLLLLLWWWWLWLLW"

    Returns: { 4, 7 }

  19. "LWWWWWWLLWWWWWLWLWWLLWLWLWLLLWLWLLLLLWLWLLWWLWLWWL"

    Returns: { 7, 42 }

  20. "WWLLWWWWLWWLWWWLLWWWWWWWLWLWLLLWWWWWWWLWWWWWWWWLLW"

    Returns: { 24, 4 }

  21. "LWWWWWWLLWWLWWWWWWLLLLLLLLWWLLWWLLLWLLLWWLWWWWLWWW"

    Returns: { 7, 39 }

  22. "LWWLWWLWWLLLW"

    Returns: { 9, 12 }

  23. "WWLLLLLL"

    Returns: { 3, 8 }

  24. "LLWWWWWWWW"

    Returns: { 10, 3 }

  25. "WLWLWLLWWLWLWWWWWWWLWLLLLLLLLLLLLWWLWLLWWWLLLWLWLW"

    Returns: { 19, 33 }

  26. "LLLLLLLLLLLL"

    Returns: { 12, 12 }

  27. "WWL"

    Returns: { 3, 3 }

  28. "WLL"

    Returns: { 3, 3 }

  29. "WWLLL"

    Returns: { 3, 5 }

  30. "LLLLLLLLLLLLL"

    Returns: { 13, 13 }

  31. "LLL"

    Returns: { 3, 3 }

  32. "WWWWWLLLLLLLLLLLLLLL"

    Returns: { 5, 20 }

  33. "LWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLW"

    Returns: { 50, 3 }

  34. "WWLL"

    Returns: { 3, 4 }

  35. "WWLLLLLLLLLLLLL"

    Returns: { 3, 15 }

  36. "WWLW"

    Returns: { 4, 3 }

  37. "WLLLLLL"

    Returns: { 3, 7 }

  38. "WWWWWW"

    Returns: { 6, 6 }

  39. "WLLLL"

    Returns: { 3, 5 }

  40. "LLLLLLWLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLWWWWWW"

    Returns: { 7, 6 }

  41. "LLLLLLLLL"

    Returns: { 9, 9 }


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: