FastPrepAll Halfway Courses Across Course Tracks
Problems/All Halfway Courses Across Course Tracks

All Halfway Courses Across Course Tracks

Crunchyroll logoCrunchyroll● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This is part three of the same Crunchyroll phone screen. Course pairs now form many tracks that can share courses. Each track runs from a course with nothing before it to a course with nothing after it. You list every course that is the halfway point of some track.

The report's examples use the same halfway rule as part two: the first of the two middles on an even track. It allows any output order and gives no limits. Our choices: the answer lists each halfway course once, sorted by character code. There are 1 to 300 pairs, no pair repeats, and no pair links a course to itself. There are no loops, at most 150 courses and at most 20,000 tracks, and groups of courses that never link to each other are allowed. Course names are 1 to 30 letters, digits, spaces or underscores, with no space at either end and no double spaces.

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

Students can choose among several tracks of courses, and different tracks may share courses. You get the course links as pairs, where [source, destination] means destination can be taken right after source.

A starting course is a course that is never a destination, and an ending course is a course that is never a source. A track starts at a starting course, follows links one at a time, and stops at an ending course. Each student follows one whole track.

For a track of L courses numbered from 0, its halfway course is the course at position (L - 1) / 2, rounded down. With an even L, this is the first of the two middle courses.

Return every course that is the halfway course of at least one track. List each course once, sorted by character code, as in standard string sorting.

Function

allHalfwayCourses(pairs: String[][]) → String[]

Examples

Example 1

pairs = [["Logic","COBOL"],["Data Structures","Algorithms"],["Creative Writing","Data Structures"],["Algorithms","COBOL"],["Intro to Computer Science","Data Structures"],["Logic","Compilers"],["Data Structures","Logic"],["Graphics","Networking"],["Networking","Algorithms"],["Creative Writing","System Administration"],["Databases","System Administration"],["Creative Writing","Databases"],["Intro to Computer Science","Graphics"]]return = ["Creative Writing","Data Structures","Databases","Networking"]
  • The starting courses are Intro to Computer Science and Creative Writing. Following the pairs from them gives 9 tracks.
  • Intro to Computer Science → Graphics → Networking → Algorithms → COBOL has 5 courses, so its halfway course is Networking (position 2).
  • Every 4-course track through Data Structures, such as Intro to Computer Science → Data Structures → Logic → COBOL, has Data Structures at position 1.
  • Creative Writing → Databases → System Administration gives Databases, and the 2-course track Creative Writing → System Administration gives Creative Writing.
  • The distinct halfway courses, sorted, are Creative Writing, Data Structures, Databases and Networking.

Example 2

pairs = [["Course_3","Course_7"],["Course_0","Course_1"],["Course_1","Course_2"],["Course_2","Course_3"],["Course_3","Course_4"],["Course_4","Course_5"],["Course_5","Course_6"]]return = ["Course_2","Course_3"]

There are two tracks. Course_0 → … → Course_6 has 7 courses, so its halfway course is Course_3. Course_0 → Course_1 → Course_2 → Course_3 → Course_7 has 5 courses, so its halfway course is Course_2.

Constraints

  • 1 <= pairs.length <= 300
  • Each pair is [source, destination] with two different course names, and no pair appears twice.
  • 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.
  • At most 150 different courses appear.
  • Following the pairs never leads back to an earlier course (there are no cycles), and there are at most 20000 tracks in total.

More Crunchyroll Phone Screen questions

  • Halfway Course in a Single TrackPHONE SCREEN · Seen Nov 2026
  • Shared Courses for Every Pair of StudentsPHONE 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

  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Work Order Critical PathHadrian · PHONE SCREENHadrian interview questions
  • Course ScheduleNykaa · PHONE SCREENNykaa interview questions
  • Longest Name Chain in a Directed Acyclic GraphOscar Health · PHONE SCREEN
  • Service Dependency Load FactorsRobinhood · PHONE SCREENRobinhood interview questions
  • Employee Hierarchy Cycle and Depth AnalysisMicrosoft · PHONE SCREENMicrosoft interview questions
  • Longest Chain BookingAirbnb · PHONE SCREENAirbnb interview questions
  • Effective Role PrivilegesSnowflake · PHONE SCREENSnowflake interview questions
All Crunchyroll interview questionsSee Crunchyroll hiring insights
Saved
class Solution {
    public String[] allHalfwayCourses(String[][] pairs) {
        // Write your code here.
    }
}
Checking account…