Triple Consecutive Sensor Codes
Problem
A machine records a status `code` on every tick. Ticks are numbered sequentially with no gaps.
**DataFrame: `tick_log`**
| Column | Type |
|---------|------|
| tick_no | int |
| code | int |
`tick_no` is unique and increases by 1 with no gaps.
Return a DataFrame with one column `repeated_code` listing every status `code` that appears in **at least three consecutive ticks**. Report each qualifying code once, in any order.
Input data
Example rows — the live problem includes the full dataset.
| tick_no | code |
|---|---|
| 1 | 7 |
| 2 | 7 |
| 3 | 7 |
| 4 | 9 |
| 5 | 7 |
Expected output
Your answer should return 1 row with the columns repeated_code.
Starter code (Pandas (Python))
import pandas as pd
def triple_run_codes(tick_log) -> pd.DataFrame:
# Your code here
return tick_logSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock