PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Vanta
  • Coding & Algorithms
  • Software Engineer

Implement a uniq-like function

Company: Vanta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement a function similar to the Unix `uniq` utility. You are given a sequence of strings representing lines of text in the order they appear in a file. Return a new sequence where **only consecutive duplicate lines are collapsed** into a single line (i.e., remove repeated adjacent duplicates but do not remove duplicates that are separated by different lines). Example: - Input: `["a","a","b","b","b","a","a","c"]` - Output: `["a","b","a","c"]` Clarify with the interviewer: - Whether input is streaming (iterator) or in-memory. - Whether comparison is case-sensitive. - Whether to support options like returning counts per group (e.g., `uniq -c`) or only the collapsed lines.

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.

Implement a function similar to the Unix `uniq` utility. You are given an in-memory list of strings representing lines of text in the order they appear in a file. Return a new list where only consecutive duplicate lines are collapsed into a single line. Important: only adjacent duplicates should be removed. If the same line appears again later after a different line, it should remain in the result. Assume comparisons are case-sensitive, and you only need to return the collapsed lines (not counts).

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.

Input: ["A", "A", "a", "a", "A"]

Expected Output: ["A", "a", "A"]

Explanation: Comparison is case-sensitive, so `A` and `a` are treated as different lines.

Hints

  1. You only need to compare each line with the most recently kept line.
  2. Be careful with the first element and with empty input.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement a Unique Lines Command - Vanta (easy)
  • Design test-run logging and query functions - Vanta (Medium)
  • Implement test failure analytics APIs - Vanta (Medium)
  • Design test logging and failure-window queries - Vanta (Medium)
  • Design streaming test logger and queries - Vanta (Medium)