PracHub
QuestionsLearningGuidesInterview 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.

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 9,000+ real questions from top companies.

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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 Adjacent-Line Uniq - Vanta (medium)
  • Implement a Unique Lines Command - Vanta (easy)
  • Order Classes by Prerequisites with Recursive DFS - Vanta (medium)
  • Remove Global Duplicates While Preserving Order - Vanta (medium)