Data Selection
hardarraysfilteringsorting
Asked at



Datadog, DoorDash, Instacart, Snowflake, Uber
Problem statement
Implement selectData(sessions, options), a utility for selecting gym session records from a data set.
[
{ user: 8, duration: 50, equipment: ['bench'] },
{ user: 7, duration: 150, equipment: ['dumbbell', 'kettlebell'] },
{ user: 1, duration: 10, equipment: ['barbell'] },
{ user: 7, duration: 100, equipment: ['bike', 'kettlebell'] },
{ user: 7, duration: 200, equipment: ['bike'] },
{ user: 2, duration: 200, equipment: ['treadmill'] },
{ user: 2, duration: 200, equipment: ['bike'] },
]
Session Fields
user: user id.duration: duration in minutes.equipment: equipment used in the session, sorted alphabetically.
Options
user: include only sessions for this user.minDuration: include only sessions with duration greater than or equal to this value.equipment: include only sessions containing every requested equipment item.merge: when true, merge sessions by user into one row per user.
When merging, sum durations and combine equipment into a sorted unique list.
Requirements & constraints
- Do not mutate input sessions.
- Equipment in merged results should be unique and alphabetically sorted.
- When `merge` is true, return users sorted by user id.
How to approach Data Selection
The strategy an interviewer expects you to reach for.
Approach First filter the sessions according to the provided options. Each option is independent, so a session must satisfy all specified filters.
Premium
The full solution is part of HelloFrontend Pro
The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.
- Runnable editor with the hidden test suite
- Progressive hints that unlock as you get stuck
- Senior-level reference solution with a line-by-line walkthrough
Already a member? Log in to open the workspace.