Gamified challenge · Hash sets
days lists the day numbers on which you worked out, in no particular order, and the same day may be logged more than once. A streak is a run of consecutive day numbers, like 4, 5, 6, 7.
Write longestStreak(days) (Python: longest_streak(days)) that returns the length of the longest streak. Repeats count once, and an empty logbook has a streak of 0.
Example: [5, 1, 3, 2, 10, 4, 11] contains days 1 to 5, so the answer is 5. Sorting works, but a hash set gets it done in O(n).
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google