Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Efficient Parsing and Analysis Function
00:00
5 left

Efficient Parsing and Analysis Function

MediumPython

Problem

Write a function to parse and analyze large sets of data efficiently.

Implement parse_and_analyze(records), where records is a list of valid comma-separated strings in the format category,value. Return a dictionary mapping each category to an object containing its record count and numeric sum. Process records in one pass and preserve the order in which categories first appear.

Input and Output

  • Input: list[str]
  • Output: dict[str, dict[str, int]]
  • Values are signed integers, and category names contain no commas.

Constraints

  • 0 <= len(records) <= 9999
  • Each record has the format category,value
  • Category names are non-empty strings containing no commas
  • Values are signed integers
  • The number of distinct categories is at most len(records)

Function Signature

def parse_and_analyze(records):
Interviewer

Your question is Efficient Parsing and Analysis Function. 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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.