Easy · Database
Employee Department Roster
Given Employee(id, name, departmentId) and Department(id, name), return Employee and Department for each employee with a matching department. Return no row for an unmatched employee or an empty department; row order does not matter.
Examples
Example 1
{
"employees": [
{"id": 1, "name": "Ava", "departmentId": 10},
{"id": 2, "name": "Ben", "departmentId": 20},
{"id": 3, "name": "Cy", "departmentId": 9}
],
"departments": [
{"id": 10, "name": "Engineering"},
{"id": 20, "name": "Sales"}
]
}Output: [{"Employee":"Ava","Department":"Engineering"},{"Employee":"Ben","Department":"Sales"}]
Example 2
{
"employees": [
{"id": 4, "name": "Dee", "departmentId": 30},
{"id": 5, "name": "Eve", "departmentId": 30}
],
"departments": [
{"id": 30, "name": "Operations"},
{"id": 40, "name": "Legal"}
]
}Output: [{"Employee":"Dee","Department":"Operations"},{"Employee":"Eve","Department":"Operations"}]
Rebuild it in the studio
20 free core interview problems with full runner & lessons; explore the complete 380+ library with Pro.