Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Longest or Shortest Order Durations

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

Your question is Longest or Shortest Order Durations. 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

Implement a solution to find the longest or shortest order durations in an analytics system.

Given a non-empty list of order records and a mode, return the extreme duration and the IDs of every order having that duration. Preserve the input order of IDs when multiple orders tie.

Input and Output

orders is a list of dictionaries with string order_id and non-negative integer duration fields. mode is either "longest" or "shortest". Return a dictionary with duration and order_ids.

Constraints

  • 1 <= len(orders) <= 10^5
  • Each order contains a unique string order_id
  • 0 <= order.duration <= 10^9
  • mode is either "longest" or "shortest"

Function Signature

def find_order_extreme(orders, mode):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output