FastPrepShared Courses for Every Pair of Students
Problems/Shared Courses for Every Pair of Students

Shared Courses for Every Pair of Students

Crunchyroll logoCrunchyroll● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This is part one of a three-part Crunchyroll technical phone screen. You get enrollment rows of student ID and course name, and you list the courses that each pair of students has in common, pairs with nothing in common included.

The report's examples show the expected pairs but allow any output order, and the only limit it gives is that each student takes a few courses. Our choices: each pair is one row of the smaller ID, the larger ID and then the shared courses. IDs are compared as numbers, courses are in character-code order, and rows are sorted by the two IDs. Student IDs are whole numbers from 0 to 1,000,000,000 with no leading zeros. Course names are 1 to 30 letters, digits, spaces or underscores, with no space at either end and no double spaces. No row repeats, and there are 1 to 300 rows, at most 30 students and at most 10 courses per student. With only one student, the answer is empty.

Our version is about 90% the same as the reported question.

A university wants to help students find courses they share with friends. Its system lists course enrollments as [studentId, course] rows.

For every pair of different students that appear in enrollments, find all the courses that both of them take. Return one row per pair: [firstId, secondId, course1, course2, ...]. Pairs that share no course are included too, and their row holds only the two IDs.

Order the result so that the answer is unique:

  • In each row, the smaller student ID (compared as numbers) comes first, and the shared courses are sorted by character code, as in standard string sorting.
  • Rows are sorted by their first ID, then by their second ID, both compared as numbers.

Function

sharedCourses(enrollments: String[][]) → String[][]

Examples

Example 1

enrollments = [["58","Linear Algebra"],["94","Art History"],["94","Operating Systems"],["17","Software Design"],["58","Mechanics"],["58","Economics"],["17","Linear Algebra"],["17","Political Science"],["94","Economics"],["25","Economics"],["58","Software Design"]]return = [["17","25"],["17","58","Linear Algebra","Software Design"],["17","94"],["25","58","Economics"],["25","94","Economics"],["58","94","Economics"]]
  • The students are 17, 25, 58 and 94, so there are 6 pairs.
  • Students 17 and 58 both take Linear Algebra and Software Design.
  • Students 25, 58 and 94 all take Economics, so each pair among them shares it.
  • Pairs 17, 25 and 17, 94 share nothing, so their rows hold only the two IDs.

Example 2

enrollments = [["0","Advanced Mechanics"],["0","Art History"],["1","Course 1"],["1","Course 2"],["2","Computer Architecture"],["3","Course 1"],["3","Course 2"],["4","Algorithms"]]return = [["0","1"],["0","2"],["0","3"],["0","4"],["1","2"],["1","3","Course 1","Course 2"],["1","4"],["2","3"],["2","4"],["3","4"]]

There are 5 students and 10 pairs. Only students 1 and 3 share courses: Course 1 and Course 2. Every other pair shares nothing.

Example 3

enrollments = [["23","Software Design"],["3","Advanced Mechanics"],["2","Art History"],["33","Another"]]return = [["2","3"],["2","23"],["2","33"],["3","23"],["3","33"],["23","33"]]

No two students take the same course, so all 6 rows hold just two IDs. IDs are ordered by number: 2 before 3 before 23 before 33.

Constraints

  • 1 <= enrollments.length <= 300
  • Each row is [studentId, course]. A student ID is an integer from 0 to 10^9 written in digits with no leading zeros.
  • A course name has 1 to 30 characters: letters, digits, spaces and underscores, with no space at the start or end and no two spaces in a row.
  • No row appears twice. At most 30 different students appear, and each student takes at most 10 courses.

More Crunchyroll Phone Screen questions

  • All Halfway Courses Across Course TracksPHONE SCREEN · Seen Nov 2026
  • Halfway Course in a Single TrackPHONE SCREEN · Seen Nov 2026
  • List Password Rule ViolationsPHONE SCREEN · Seen Jan 2026
  • Map Order User IDs to Customer NamesPHONE SCREEN · Seen Jan 2026

Similar questions at other companies

  • Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
  • Remove Later Anagrams From a ListBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Employees With Shared InterestsPalantir · PHONE SCREENPalantir interview questions
  • Group AnagramsWorkday · PHONE SCREEN
  • Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
  • Find Duplicate File GroupsAnthropic · PHONE SCREENAnthropic interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Group AnagramsMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
  • Stable Top K Frequent WordsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Find Duplicate Image FilesAbnormal Security · PHONE SCREEN
All Crunchyroll interview questionsSee Crunchyroll hiring insights
Saved
class Solution {
    public String[][] sharedCourses(String[][] enrollments) {
        // Write your code here.
    }
}
Checking account…