Employee Friendship Adjacency from CSV
Updated
Problem statement
You receive two complete CSV strings. employeesCsv has the header employee_id,name,department and one record per employee. friendshipsCsv has the header id_1,id_2 and one record per friendship. Parse both datasets into employee and friendship records, then build the adjacency mapping for every employee.
Friendships are undirected: each listed pair makes both employees friends. All IDs in a friendship exist, there are no duplicate employees or undirected friendship pairs, and IDs need not be consecutive. Include employees with no friends.
Return the mapping as an int[][]. Each row starts with an employee ID and continues with all of that employee's friend IDs. An isolated employee has a one-element row. Sort the rows by employee ID, and sort the friend IDs in each row, both in ascending numeric order.
The CSV uses a comma between fields, with no quotes, and a newline between records. A final newline is optional. There are no blank data lines or spaces around commas. Names and departments may contain internal spaces. A header with no data records represents an empty dataset; an empty employee dataset has no friendships.
Function
friendshipAdjacency(employeesCsv: String, friendshipsCsv: String) → int[][]Examples
Example 1
employeesCsv = "employee_id,name,department\n1,Richard,Engineering\n2,Erlich,HR\n3,Monica,Business\n4,Dinesh,Engineering\n6,Carla,Engineering"friendshipsCsv = "id_1,id_2\n1,2\n1,3\n2,4"return = [[1,2,3],[2,1,4],[3,1],[4,2],[6]]The three undirected friendships give employee 1 friends 2 and 3, employee 2 friends 1 and 4, employee 3 friend 1, and employee 4 friend 2. Employee 6 is present even though she has no friends.
Example 2
employeesCsv = "employee_id,name,department\n40,Ada,Research\n7,Lin,People Ops\n99,Sam,Research"friendshipsCsv = "id_1,id_2\n99,7"return = [[7,99],[40],[99,7]]IDs are nonconsecutive and records arrive out of order. The returned rows start with 7, 40, and 99. Employee 40 remains isolated.
Constraints
- There are 0 to 500 employees and 0 to 5000 friendships.
- Each employee ID is an integer from 1 to 10^9, written without leading zeros. Friendships connect two different employees.
- Each name and department has 1 to 50 characters from ASCII letters, digits, spaces, hyphens, and underscores, and contains a non-space character.
employeesCsv.length <= 60000andfriendshipsCsv.length <= 120000. Both inputs start with the headers given above.
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
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Find Root IDs from Parent ReferencesZip · PHONE SCREENZip interview questions
- Resolve Key-Value ChainsIndeed · PHONE SCREENIndeed 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