Implement global line uniqueness: keep only the first occurrence of each distinct input line, even when duplicates are not adjacent.
Function Signature
unique_lines(lines: list[str]) -> list[str]
Rules
-
Compare complete strings exactly and case-sensitively.
-
Preserve the input order of first occurrences.
-
An empty string is a valid line and may appear once in the output.
-
Do not trim spaces or normalize the contents.
-
Input strings represent lines without their terminating newline characters.
These comparison and order rules are explicit conventions for the global-uniqueness task.
Constraints
-
0 <= len(lines) <= 200000
.
-
Each line contains printable ASCII characters with code points 32 through 126, or is empty.
-
Total input character count is at most 2000000.
-
Do not mutate the input.
Examples
Input: lines = ["alpha","beta","alpha","beta","gamma"]
Output: ["alpha","beta","gamma"]
Input: lines = ["","A","a",""," A","A"]
Output: ["","A","a"," A"]
Input: lines = []
Output: []