Keep the First Occurrence of Every Globally Unique Line

Read the full interview experience this question came from →

Quick Overview

Remove repeated lines globally while preserving first-occurrence order, exact case, spaces, and empty lines.

Keep the First Occurrence of Every Globally Unique Line

Company: Vanta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

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: `[]`

Overview: Remove repeated lines globally while preserving first-occurrence order, exact case, spaces, and empty lines.

Read the full Vanta Software Engineer interview experience this question came from

|Home/Coding & Algorithms/Vanta
Vanta logo
Vanta
Sep 12, 2026
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

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: []

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...