Department Headcounts and External Friendships
Updated
Problem statement
Each string in employeeRecords contains an employee ID, name, and department. Each string in friendshipRecords contains two employee IDs that are friends. Friendships are undirected.
For every department, return its total number of employees and the number of distinct employees in that department who have at least one direct friend in a different department. An employee with several external friends counts once. A friend of a friend does not qualify unless that person is also a direct friend.
For this exercise, assume the source's formal two-count definition governs: the first count includes every employee in the department, including employees who only have same-department friends. Such friendships do not increase the second count.
For this exercise, assume employee records use the unquoted form id,name,department and friendship records use id1,id2, with ASCII commas and no spaces around them. There are no headers. IDs are unique, and friendship IDs exist and differ. Repeated friendships, including reversed copies, have the same effect as one friendship.
Return a String[][] with rows [department, totalEmployees, employeesWithExternalFriends], where counts are decimal strings. For this exercise, assume rows sort by department in ascending ASCII order. Empty employee input returns no rows. Department names are case-sensitive and preserve internal spaces.
Function
departmentFriendshipStats(employeeRecords: String[], friendshipRecords: String[]) → String[][]Examples
Example 1
employeeRecords = ["1,Ada,Engineering","2,Bo,HR","3,Cam,Engineering","4,Dee,Engineering","8,Eli,HR"]friendshipRecords = ["1,2","1,8","3,4"]return = [["Engineering","3","1"],["HR","2","2"]]Engineering has employees 1, 3, and 4; only employee 1 has an external friend. Both HR employees, 2 and 8, are directly friends with employee 1, so HR has two qualifying employees. The internal friendship between 3 and 4 does not change either headcount.
Example 2
employeeRecords = ["9,A,Ops","2,B,Ops","7,C,Research"]friendshipRecords = ["9,2","2,9"]return = [["Ops","2","0"],["Research","1","0"]]The repeated internal friendship gives no employee an external friend. Both departments retain their full headcounts, including the isolated Research employee.
Constraints
- For this exercise, assume
0 <= employeeRecords.length <= 500and0 <= friendshipRecords.length <= 5000. - IDs are integers from 1 to 10^9, written without leading zeros.
- Each name and department has 1 to 50 ASCII letters, digits, spaces, hyphens, or underscores, with no leading or trailing spaces.
- Each employee record has 5 to 112 characters; each friendship record has 3 to 21 characters.
- All records satisfy the stated grammar. Employee IDs are unique, and every friendship references two different existing employees.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Find Minimum City HopsAmazon · OA
- Shortest Path from Encoded Graph EdgesBitGo · OABitGo interview questions
- Count Distinct Word MeaningsDuolingo · OADuolingo interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
- Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Sentence Equivalence with SynonymsRead AI · PHONE SCREEN
- Resolve Variable Equations with Dependency ErrorsMotive · PHONE SCREENMotive interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions