Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
2D Array Compression With Indices
00:00
5 left

2D Array Compression With Indices

EasyPython

Problem

Applied Intuition simulation assets may store repeated 2D vertices. Implement a compression function that keeps one copy of each distinct vertex and replaces every original vertex with the index of its retained copy.

Preserve the order in which unique vertices first appear. Two vertices are equal when their coordinate lists contain the same values in the same order.

Formal Specification

Given vertices, a list of n coordinate lists, return a two-element list:

  1. unique_vertices: the distinct coordinate lists in first-occurrence order.
  2. indices: a list of length n, where indices[i] is the index of vertices[i] in unique_vertices.

Each coordinate list has the same positive dimension, and coordinates are integers. Do not mutate the input.

Constraints

  • 0 <= len(vertices) <= 100,000
  • 1 <= len(vertices[i]) <= 8 when vertices is non-empty
  • -10^9 <= vertices[i][j] <= 10^9
  • All coordinate lists have the same dimension
  • The input must not be mutated

Function Signature

def compress_vertices(vertices):
Interviewer

Your question is 2D Array Compression With Indices. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.