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
CSV Data Aggregation with Errors
00:00
5 left

CSV Data Aggregation with Errors

MediumPython

Problem

Given CSV data of employees (Name, Department, Years of Experience), perform an operation such as finding the maximum experience or counting employees in a department, treating the data as erroneous: fields may be empty or of the wrong type and must be ignored in aggregations.

Asked in the HackerRank coding round stage. The input is a CSV string with a header row. Implement employee_aggregate(csv_data, operation, department=None): return the maximum valid experience for "max_experience", or the count of valid employees in department for "count_department". A valid row has exactly three nonempty fields, a nonnegative integer experience, and a matching department when counting. Return None when no valid experience exists.

Constraints

  • The CSV string contains a header row.
  • Each valid data row has three fields: name, department, and years of experience.
  • 0 <= number of data rows <= 1000.
  • Valid years of experience are nonnegative integers.
  • operation is either "max_experience" or "count_department".
  • department is provided for "count_department" operations.

Function Signature

def employee_aggregate(csv_data, operation, department=None):
Interviewer

Your question is CSV Data Aggregation with Errors. 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.