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
Stable Sort by Timestamp and Severity
00:00
5 left

Stable Sort by Timestamp and Severity

MediumPython

Problem

Dell PowerStore monitoring tools receive event records that must be displayed consistently. Implement a sorting algorithm of your choice to return the records ordered by timestamp ascending, then by severity descending. Records with identical keys must retain their original relative order.

Do not use the built-in sort() or sorted() functions, and do not modify the input list.

Formal Specification

Implement sort_powerstore_events(events). The input is a list of dictionaries, where each dictionary contains:

  • id: a string identifying the event
  • timestamp: an integer timestamp
  • severity: an integer from 1 through 5, where 5 is most severe

Return a new list containing the same dictionaries in the required order. The algorithm must be stable.

Constraints

  • 0 <= len(events) <= 100,000
  • 0 <= timestamp <= 10^12
  • 1 <= severity <= 5
  • Every record contains valid id, timestamp, and severity fields

Function Signature

def sort_powerstore_events(events):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

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.