FastPrepEmployee Friendship Adjacency from CSV

Employee Friendship Adjacency from CSV

Intuit logoIntuit● EasyNEW GRADOA

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 <= 60000 and friendshipsCsv.length <= 120000. Both inputs start with the headers given above.

More Intuit Online Assessment questions

Similar questions at other companies

Interview reports that mention this question

Intuit interview experiences

All Intuit interview questionsSee Intuit hiring insights
Saved
class Solution {
    public int[][] friendshipAdjacency(String employeesCsv, String friendshipsCsv) {
        // Write your code here
    }
}

Not a valid String

Checking account…