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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Embedding Index Sort and Optimization
00:00
5 left

Embedding Index Sort and Optimization

MediumPython

Problem

Given embeddings, perform an index sort (ascending and descending) and write the code in Notepad, then optimize the approach.

Asked in the VP Technical Interview stage. Focus was on DSA fundamentals, hash maps/hashing, and optimization thinking.

Implement a function that takes a list of numeric embedding scores and returns the indices that would sort the list in ascending order and in descending order.

Function

sort_embedding_indices(embeddings)

Input

  • embeddings: a list of integers or floats

Output

  • Return a dictionary with two keys:
    • ascending: indices sorted by embedding value from smallest to largest
    • descending: indices sorted by embedding value from largest to smallest

If two values are equal, preserve their original relative order in both outputs.

Constraints

  • 1 <= len(embeddings) <= 10^5
  • Each embedding value is an integer or float
  • Equal values must preserve original relative order
  • Return index permutations, not the sorted values

Function Signature

def sort_embedding_indices(embeddings):
Interviewer

Your question is Embedding Index Sort and Optimization. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.