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
API Data Transformation Function
00:00
5 left

API Data Transformation Function

HardPython

Problem

The Justworks People frontend receives employee records in an API-specific shape. Transform the response into department groups that are ready to render, while filtering inactive benefits, removing duplicate plans, and applying deterministic sorting.

Formal Specification

Implement transform_justworks_people(response). The input is a dictionary containing a data array. Each employee has id, first_name, last_name, employment_status, an optional department object with id and name, and a benefits array. Each benefit has plan_id, plan_name, and status.

Return a list of dictionaries with this shape:

  • department_id: the department ID, or null when the employee has no department
  • department: the department name, or "Unassigned" when there is no department
  • employees: transformed employee objects containing id, name, status, and active_plans

Include only benefits whose status is "active". Deduplicate benefits by plan_id, retain the first name encountered for each plan, and sort plan names alphabetically. Group employees by department, sort employees by last name, first name, then ID, and sort department groups by department name.

Constraints

  • 1 <= len(response["data"]) <= 10^5
  • Employee and department IDs are unique identifiers represented by strings or integers
  • Each employee has 0 <= len(benefits) <= 20 benefits
  • Each benefit has a non-empty plan_id and plan_name
  • Employee and department ordering must be deterministic

Function Signature

def transform_justworks_people(response):
Interviewer

Your question is API Data Transformation 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.