Step Goal Streaks
Implement a class StepLog that records one step count per day and tracks streaks of days that reach a goal. A day meets the goal when its steps are at least goal. Write these methods:
StepLog(goal)starts with no days.log_day(steps)records the next day. Returns the current streak: the number of days in a row that met the goal, ending with the most recent day (0if that day missed the goal).fix_last(steps)replaces the steps of the most recent day and returns the current streak afterwards. Returns-1if no day has been logged (then nothing changes).get_best_streak()returns the longest run of days in a row that met the goal, or0if there is none. A fixed day counts with its new steps.get_total_steps()returns the sum of the steps of all days.
The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.
Example 1
StepLog(5000)
log_day(6000) returns 1
log_day(5000) returns 2
log_day(7000) returns 3
get_best_streak() returns 3
fix_last(100) returns 0
get_best_streak() returns 2
log_day(8000) returns 1
Exactly 5000 steps meets the goal, so the first three days make a streak of 3. Fixing the third day to 100 breaks it, and the best streak drops to 2.
Constraints
1 <= goal <= 100000 <= steps <= 20000- Each test makes
1to40method calls after the constructor.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.