FastPrepMiddle Element of a Linked List
Problems/Middle Element of a Linked List

Middle Element of a Linked List

Expedia logoExpedia● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two Expedia intern write-ups cover locating the center node of a singly linked list. One, listed in 2012 for a Software Developer Intern, wanted several methods (5 in all) with a running time for each, and then the quickest one. It kept the count of values odd, and it uses the word median, explained there as the center element.

The other, listed in 2024 for a Mobile Development Intern, gives the question in a single line. Neither sets limits or covers lists with an even count. Here, you return the value held by the center node. With an even count, take the later of the two center nodes. A list has 1 to 1000 nodes, and each value is a whole number from -10^5 to 10^5. Only that value is checked, and the editorial compares several methods and their running times.

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

You are given head, the first node of a singly linked list. Return the value stored in the middle node of the list.

Number the nodes 1, 2, ..., n starting from head.

  • If n is odd, the middle node is node (n + 1) / 2.
  • If n is even, there are two middle nodes, n / 2 and n / 2 + 1. Return the value of the second one, node n / 2 + 1.

The middle is about position in the list, not about the size of the values. The values can be in any order.

Function

middleValue(head: ListNode) → int

Examples

Example 1

head = [4,9,2,7,5]return = 2
head
49275

The list has 5 nodes, an odd number. The middle node is node (5 + 1) / 2 = 3, which holds 2.

Example 2

head = [3,8,1,6]return = 1
head
3816

The list has 4 nodes, an even number, so there are two middle nodes: node 2, which holds 8, and node 3, which holds 1. Return the value of the second one, 1.

Example 3

head = [-7]return = -7
head
-7

A list with one node has that node as its middle, so the answer is -7.

Constraints

  • 1 <= n <= 1000, where n is the number of nodes.
  • Every node value is between -10^5 and 10^5.
  • Values may repeat.

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
  • Maximum Supplier ProfitONSITE INTERVIEW · Seen Aug 2024

Similar questions at other companies

  • Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
  • Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
  • Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Build and Check a Palindrome Linked ListOmnissa · ONSITE INTERVIEWOmnissa interview questions
  • Reverse a Singly Linked ListGEP · ONSITE INTERVIEW
  • Merge Two Sorted Linked ListsApple · ONSITE INTERVIEWApple interview questions
  • Reverse a Singly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Reverse Linked ListThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Detect a Linked-List CycleGoogle · ONSITE INTERVIEWGoogle interview questions
  • Detect a Cycle in a Linked ListPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions

Interview reports that mention this question

  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public int middleValue(ListNode head) {
        // Write your code here.
    }
}
Checking account…