PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to perform duplicate detection and compression of sequences of fixed-length tuples, exercising skills in data structures, mapping/hash concepts, array manipulation, and preserving first-seen ordering.

  • medium
  • Applied
  • Coding & Algorithms
  • Software Engineer

Compress vertices into uniques and indices

Company: Applied

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an array of vertices (a 2D array). Each vertex may repeat. Implement a simple “compression” that produces: 1. `unique_vertices`: the list of unique vertices, **preserving the order of first appearance**. 2. `indices`: for each vertex in the original array, the index of its corresponding vertex in `unique_vertices`. ### Input - `vertices`: a list of `n` vertices - each vertex is a fixed-length list/tuple of integers (e.g., 3D vertex) ### Output - `unique_vertices`: list of unique vertices in first-seen order - `indices`: integer list of length `n` ### Example Input: ``` [[2,2,2], [0,1,0], [2,1,2], [0,1,0]] ``` Output: ``` unique_vertices = [[2,2,2], [0,1,0], [2,1,2]] indices = [0, 1, 2, 1] ``` ### Notes / Constraints - Treat two vertices as equal if all coordinates match. - Aim for efficient time complexity (better than O(n^2) if possible).

Quick Answer: This question evaluates a candidate's ability to perform duplicate detection and compression of sequences of fixed-length tuples, exercising skills in data structures, mapping/hash concepts, array manipulation, and preserving first-seen ordering.

Return unique vertices in first-seen order and the index mapping for each original vertex.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([[2,2,2], [0,1,0], [2,1,2], [0,1,0]],)

Expected Output: {'unique_vertices': [[2, 2, 2], [0, 1, 0], [2, 1, 2]], 'indices': [0, 1, 2, 1]}

Explanation: Prompt example.

Input: ([],)

Expected Output: {'unique_vertices': [], 'indices': []}

Explanation: No vertices.

Input: ([[1,2], [1,2], [1,3]],)

Expected Output: {'unique_vertices': [[1, 2], [1, 3]], 'indices': [0, 0, 1]}

Explanation: Repeated first vertex.

Hints

  1. Pick a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
Last updated: Jun 27, 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
  • 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

  • Multi-Agent Collision Simulator (Unicycle Kinematics) - Applied (medium)
  • Merge Overlapping Collinear Segments - Applied (hard)
  • Implement a Fixed-Capacity Deque - Applied (medium)
  • Implement Nested Transactional Key-Value Store - Applied (hard)
  • Merge overlapping 2D line segments - Applied (medium)