CCisco·DSAGrade 8Online Assessment
Pack Consecutive Duplicates Into Sublists
Problem
Group consecutive equal elements of a list into sublists (run-length grouping).
Example
[a,a,b,c,c,c] -> [[a,a],[b],[c,c,c]]
Constraints
- 0 ≤ n ≤ 10^4
Approach
Single pass comparing to the previous element. Reported Cisco question.
added 6 days ago