Coding problem
Staff by department
The task
The intranet's directory page receives a list of departments and shows the people in each of them, one department after another.
Complete StaffIn(List<Employee> staff, List<string> departments). Employee is a record with a Name and a Department. For each department in departments, in that order, add the names of the employees in that department, in the order they appear in staff. A department that nobody works in adds no names, and a department asked for twice is answered twice. Departments match exactly, letter case included. Either list may be empty. The lists and employees are never null.
Signature
public record Employee(string Name, string Department); public static List<string> StaffIn(List<Employee> staff, List<string> departments)
Examples
staff [("cara", "sales"), ("ben", "it"), ("amy", "sales")], departments ["it", "sales"]→["ben", "cara", "amy"]. it comes first because it was asked first; cara and amy keep their order in the staff list.staff [("cara", "sales")], departments ["hr"]→[]. Nobody works in hr, so it adds no names.
Limits: Up to 200,000 employees in up to 20,000 departments, and up to 100,000 departments asked.
The tests check: no departments asked, an empty staff list, an unknown department, departments in the order asked, names in staff-list order, a department asked twice, letter case in department names, and 100,000 requests against 200,000 employees in time.
Hints
Your code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public record Employee(string Name, string Department);
public static class Solution
{
// The names in each requested department, department by department, names in staff-list order.
public static List<string> StaffIn(List<Employee> staff, List<string> departments)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.