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

Table Data Transformation Function

EasyPython

Problem

An Airtable Interface may need to display records grouped by a selected field. Given a list of record objects, transform them into one summary object per group while preserving the order in which groups first appear.

Implement group_records(records, group_field, value_field, label_field).

For each group:

  1. Use record[group_field] as the group name.
  2. Add record[value_field] to the group's numeric total.
  3. Count the number of records in the group as count.
  4. Collect distinct values from record[label_field] in first-seen order as labels.
  5. Return groups in first-seen order. Within labels, preserve first appearance order.

Each input record contains all requested fields. Values in label_field are strings, and values in value_field are integers or floats. Do not mutate the input records.

Formal Specification

Input: records, a list of dictionaries, plus three strings naming fields. Return a list of dictionaries with keys group, total, count, and labels.

Constraints

  • 0 <= len(records) <= 10^5
  • Each record contains group_field, value_field, and label_field
  • Group and label values are hashable
  • Numeric values fit standard Python integer or floating-point types
  • Do not mutate records or the input list

Function Signature

def group_records(records, group_field, value_field, label_field):
Interviewer

Your question is Table 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.