FastPrepMiddle Course of a Course Track
Problems/Middle Course of a Course Track

Middle Course of a Course Track

WhatNot logoWhatNot● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: From the same early-2023 Karat screen for an intern role: the second coding question, about finding the course in the middle of a track. By the time the poster reached it, about 15 minutes were left, which was not enough to debug. Like the first question, it comes from the question bank the poster says Karat reuses.

The post names the task and gives no details. Here the pairs describe one straight track in any order, and a track with an even number of courses returns the earlier middle course. The editorial also covers a follow-up with several tracks.

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

A course track is a sequence of courses where each course must be taken right before the next one. You are given a track as a list of pairs [prerequisite, course], meaning prerequisite comes immediately before course. The pairs can come in any order.

Together, the pairs link every course into one straight line: exactly one course has no prerequisite, every other course has exactly one, and no course comes immediately before two different courses.

Return the course in the middle of the track. If the track has k courses, this is the course at position (k - 1) / 2, rounded down and counted from 0 at the first course. So when k is even, return the earlier of the two middle courses.

Course names are case-sensitive: "Art" and "art" are different courses.

Function

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

Examples

Example 1

pairs = [["Statistics","Machine Learning"],["Calculus","Statistics"],["Machine Learning","Deep Learning"]]return = "Statistics"

The track is Calculus, Statistics, Machine Learning, Deep Learning. It has 4 courses, so the two middle courses are Statistics and Machine Learning; return the earlier one.

Example 2

pairs = [["Intro","Data Structures"],["Algorithms","Compilers"],["Data Structures","Algorithms"],["Compilers","Thesis"]]return = "Algorithms"

The track is Intro, Data Structures, Algorithms, Compilers, Thesis. With 5 courses, the middle one is at position 2.

Example 3

pairs = [["Spanish 1","Spanish 2"]]return = "Spanish 1"

Two courses: the earlier of the two middle courses is the first one.

Example 4

pairs = [["Art","ART"],["art","Art"]]return = "Art"

Names are case-sensitive, so these are three different courses. The track is art, Art, ART, and the middle course is Art.

Constraints

  • 1 <= pairs.length <= 104
  • pairs[i].length == 2
  • Each course name has 1 to 20 characters: English letters, digits and spaces, with no space at the start or end and no two spaces in a row.
  • The pairs form one straight track of pairs.length + 1 different courses, with no cycle and no branch.

More WhatNot Phone Screen questions

  • Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 2026
  • Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
  • Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
  • Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • 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
  • 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

Interview reports that mention this question

  • Whatnot interviews · March 2026 (Part 2 of 2)

WhatNot interview experiences

  • Whatnot OA · November 2023
  • Whatnot interviews · November 2023
  • Whatnot interviews · February 2024
  • Whatnot interviews · March 2024
  • Whatnot OA · April 2024
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public String middleCourse(String[][] pairs) {
        // write your code here
    }
}
Checking account…