Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
Transform API Response for UI
00:00
5 left

Transform API Response for UI

MediumPython

Problem

The Coforge iNFINI frontend receives dashboard records in a raw API response. Transform the response into a display-ready structure by keeping the newest record for each id, grouping records by status, and sorting each group for consistent rendering.

Formal Specification

Implement transform_response(raw_response). The input is a dictionary with an items key containing a list of record dictionaries. Each record contains:

  • id: a unique string identifying the record, although duplicate IDs may occur
  • title: a display title string
  • status: one of failed, pending, or active
  • priority: an integer from 1 to 5
  • updatedAt: an ISO 8601 UTC timestamp in YYYY-MM-DDTHH:MM:SSZ format

For duplicate IDs, retain the record with the later updatedAt. If timestamps are equal, retain the record with the higher priority.

Return a dictionary with a sections key. It must contain one section for each status in this order: failed, pending, active. Each section has status and cards keys. A card contains only id, title, priority, and updatedAt.

Within each section, sort cards by descending priority, then descending updatedAt, then ascending id.

Constraints

  • 1 <= len(raw_response["items"]) <= 10^5
  • Each id has at most 100 duplicate records
  • status is one of failed, pending, or active
  • priority is an integer from 1 through 5
  • updatedAt is a valid ISO 8601 UTC timestamp in fixed-width format

Function Signature

def transform_response(raw_response):
Interviewer

Your question is Transform API Response for UI. 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.