Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Data Structure Tradeoffs
00:00
5 left

Data Structure Tradeoffs

MediumPython

Problem

Explain the pros and cons of two different data structures you have used and when you would pick each.

Implement unique_in_order(items) to return the distinct values from items in their first-seen order. Your implementation must use two data structures and should make their different roles clear. Discuss the time, space, ordering, lookup, and duplicate-handling trade-offs.

Signature: def unique_in_order(items):

Input is a list of hashable values. Return a list containing each value once, preserving its first occurrence.

Examples: ["hot", "new", "hot"] returns ["hot", "new"]; [3, 1, 3, 2] returns [3, 1, 2].

Constraints: 1 <= len(items) <= 10^4.

Constraints

  • 1 <= len(items) <= 10^4
  • Each item is hashable
  • The output must preserve first-seen order

Function Signature

def unique_in_order(items):
Interviewer

Your question is Data Structure Tradeoffs. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.