FastPrepHalfway Course in a Single Track
Problems/Halfway Course in a Single Track

Halfway Course in a Single Track

Crunchyroll logoCrunchyroll● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This is part two of the same Crunchyroll phone screen. Course pairs link each course to the one taken next. All the pairs form one straight track, and you return the course where a student is halfway through.

The report's examples fix the even case: take the first of the two middle courses. It gives no limits or name format. Our choices: there are 1 to 1,000 pairs, so a track always has at least two courses. The pairs always join every course into one straight track with no branches, loops or repeated pairs, and each course appears once on it. Course names are 1 to 30 letters, digits, spaces or underscores, with no space at either end and no double spaces. The answer is the course name itself.

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

Students in a program take courses along a track. You get the track as pairs, where [source, destination] means destination is taken right after source. The pairs come in any order, and together they form one straight track: every course except the first has exactly one course right before it, and every course except the last has exactly one course right after it.

Return the course a student is taking when they are halfway through the track. If the track has L courses numbered from 0, this is the course at position (L - 1) / 2, rounded down. So when L is even, return the first of the two middle courses.

Function

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

Examples

Example 1

pairs = [["Logic","Networking"],["Compilers","Logic"],["Algorithms","Compilers"],["Data Structures","Algorithms"],["Intro to Computer Science","Data Structures"]]return = "Algorithms"
  • The track is Intro to Computer Science → Data Structures → Algorithms → Compilers → Logic → Networking, which has 6 courses.
  • With an even count there are two middle courses, Algorithms (position 2) and Compilers (position 3). Return the first one: Algorithms.

Example 2

pairs = [["Networking","Graphics"],["Logic","Networking"],["Compilers","Logic"],["Algorithms","Compilers"],["Data Structures","Algorithms"],["Intro to Computer Science","Data Structures"]]return = "Compilers"

Graphics now follows Networking, so the track has 7 courses. The single middle course is at position 3: Compilers.

Constraints

  • 1 <= pairs.length <= 1000
  • Each pair is [source, destination] with two different course names.
  • 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.
  • The pairs link all the courses into one track with no branches, no cycles and no repeated pair, so the track has pairs.length + 1 courses.

More Crunchyroll Phone Screen questions

  • All Halfway Courses Across Course TracksPHONE 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

  • 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
  • Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN
  • Find Duplicate Files in a FilesystemHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Shortest Word Transformation SequenceReddit · PHONE SCREENReddit interview questions
  • Evaluate Live Spreadsheet ExpressionsStrala · PHONE SCREEN
All Crunchyroll interview questionsSee Crunchyroll hiring insights
Saved
class Solution {
    public String halfwayCourse(String[][] pairs) {
        // Write your code here.
    }
}
Checking account…