Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Embedding Index Sort and Optimization

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Embedding Index Sort and Optimization. Start with the requirements on the right.

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.

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

def 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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output