Compress Consecutive Sensor States

Compress a list of sensor-state strings into [state, count] pairs for consecutive runs. Preserve run order: equal states separated by a different state must stay in separate runs. Empty input returns []. Empty strings are valid states.

Difficulty: intermediate

Examples

  • [["ok","ok","warn","warn","ok"]][["ok",2],["warn",2],["ok",1]]

Your solution

Python

Results

Python starts when you run or submit this challenge.

Back to Lesson