Premium problem95. Longest Winning Streak

Hard Locked

matches has columns player_id, match_date (datetime) and result, where result is "W" or "L".

Within each player, order their matches by date and find the longest run of consecutive wins. Return a DataFrame with columns player_id and streak holding every player tied for the longest streak overall, sorted by player_id, with the index renumbered from 0.

A player who never won has a streak of 0 and can only appear if nobody ever won.

Input

  player_id match_date result
0        p1 2022-01-01      W
1        p1 2022-01-02      W
2        p1 2022-01-03      L
3        p1 2022-01-04      W
4        p2 2022-01-01      W
5        p2 2022-01-02      W
6        p2 2022-01-03      W

Output

  player_id  streak
0        p2       3

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)