Longest Winning Streak
A team's season is written as a string games of W (a win) and L (a loss), one letter per game, in the order they were played. The league allows the team to replay one lost game, and the team would win the replay.
Return the length of the longest winning streak the team could have after replaying at most one loss: the most games in a row that would all be wins.
Examples
games = "WWLWWWLW" → 6
games = "LLL" → 1
games = "WWWW" → 4
games = "WLWLW" → 3In the first example, replaying the first loss turns WWLWWW into six wins in a row. In the second, one replay gives a streak of one.
Constraints
- Between 0 and 20,000 games, each
WorL. - Aim for O(n): look at each game a constant number of times.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 8 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.