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
Efficient Data Transformation Script
00:00
5 left

Efficient Data Transformation Script

MediumPython

Problem

Write an efficient script to process or transform a given dataset, focusing on performance and scalability.

Implement process_dataset(records). The input is an array of maps, each containing a string key and integer value. Return an array containing one summary map per distinct key, with fields key, count, and total. Sort summaries by descending total, then ascending key for ties. The solution should avoid comparing every pair of records and should scale linearly with the number of input records before the final sort.

Constraints

  • 0 <= records.length <= 5000
  • Each record contains exactly one string key and one integer value
  • 1 <= key.length <= 100
  • -10^9 <= value <= 10^9
  • Output ordering is descending total, then ascending key

Function Signature

def process_dataset(records):
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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.