Season form guide
EasyOnline Assessment
Compute the best winning and losing streaks in a football team's season.
results lists the team's matches in the order they were played, each one "W" (win), "D" (draw) or "L" (loss). A draw counts as neither a win nor a loss, and it is treated as a short pause in a streak, not an interruption:
- A winning streak is a run of wins. A single draw between two wins does not break it (it simply isn't counted), but a loss breaks it, and so do two or more draws in a row.
- A losing streak works the same way with losses.
- The length of a streak is the number of wins (or losses) in it. Streaks start fresh after a break:
W D D Wis two streaks of length 1, whileW D Wis one streak of length 2. A win or a loss ends the other kind of streak immediately, soW D Lleaves no winning streak running.
Input: results, a list of strings.
Output: a list [bestWins, bestLosses, finishedAt]. bestWins and bestLosses are the longest winning and losing streaks of the season (0 if the team never won, or never lost). finishedAt is the 0-based index of the match that first brought a winning streak up to length bestWins, or -1 if bestWins is 0. If several streaks reach the same best length, the earliest one counts.
Example 1
- Input:
- [["W","W","D","W","L","L"]]
- Output:
- [3,2,3]
- Explanation
- A single draw does not break a streak, so
W W D Wis a winning streak of 3 wins, completed at match 3 (counting from 0). The loss at match 4 resets it, and the two losses at the end give a losing streak of 2. Answer[3, 2, 3].
Example 2
- Input:
- [["W","D","D","W","W","L","D","L"]]
- Output:
- [2,2,4]
- Explanation
- Two draws in a row break every streak. The first
Wis a streak of 1 that dies atD D. The next two wins give a streak of 2, completed at match 4. ThenL D Lis a single draw inside a losing streak, so 2 losses. Answer[2, 2, 4].
Example 3
- Input:
- [["D","D","D"]]
- Output:
- [0,0,-1]
- Explanation
- Draws are never wins or losses, so both streaks are 0 and no match completes a winning streak:
[0, 0, -1].
Constraints
0 <= results.length <= 500- each result is
"W","D"or"L"