Implement a uniq-like function
Company: Vanta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's ability in sequence and string processing, including managing state across adjacent elements and handling interface assumptions such as streaming versus in-memory input and case-sensitive comparisons; it belongs to the Coding & Algorithms category and the string-manipulation/data-processing domain.
Constraints
- 0 <= len(lines) <= 100000
- Each element of `lines` is a string
- Comparison is case-sensitive
- Return only the collapsed lines; do not return counts
Examples
Input: ["a", "a", "b", "b", "b", "a", "a", "c"]
Expected Output: ["a", "b", "a", "c"]
Explanation: Consecutive duplicates are collapsed, but the later `a` group is kept because it is separated by `b`.
Input: []
Expected Output: []
Explanation: Empty input should return an empty list.
Input: ["x"]
Expected Output: ["x"]
Explanation: A single line has no duplicates to collapse.
Input: ["a", "b", "a", "b"]
Expected Output: ["a", "b", "a", "b"]
Explanation: Duplicates that are not adjacent should not be removed.