Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

ES6 Rewrite a Function

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is ES6 Rewrite a Function. Start with the requirements on the right.

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.

Problem

Apex Systems Candidate Hub stores a chronological stream of candidate status events. Rewrite the legacy status-summary logic using modern ES6-style collection and transformation techniques. Given the events, determine each candidate's final status, then count final statuses by recruiting team.

Implement the equivalent algorithm in the required function signature. Each event has a candidate ID, team, status, and integer timestamp. A candidate may appear in multiple events, but timestamps for the same candidate are unique.

Formal Specification

Input is an array of objects with fields candidateId, team, status, and timestamp. Return an object whose keys are team names. Each team maps to an object containing status names and the number of candidates whose latest event has that status. Include only teams and statuses present in the input. The order of object keys does not matter.

Example 1:

Input: events = [{candidateId: "c1", team: "Cloud", status: "screen", timestamp: 2}, {candidateId: "c1", team: "Cloud", status: "interview", timestamp: 5}, {candidateId: "c2", team: "Cloud", status: "screen", timestamp: 3}]
Output: {"Cloud": {"interview": 1, "screen": 1}}

c1 ends in interview, while c2 remains in screen.

Example 2:

Input: events = [{candidateId: "c7", team: "Security", status: "rejected", timestamp: 4}, {candidateId: "c8", team: "Cloud", status: "offer", timestamp: 1}]
Output: {"Security": {"rejected": 1}, "Cloud": {"offer": 1}}

Constraints

  • 0 <= events.length <= 10^5
  • Each event contains candidateId, team, status, and timestamp
  • IDs, team names, and statuses are non-empty strings
  • 0 <= timestamp <= 10^9
  • Timestamps for one candidate are unique

Function Signature

def summarize_candidate_status(events):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output