FastPrepReverse a Linked List in Groups of K
Problems/Reverse a Linked List in Groups of K

Reverse a Linked List in Groups of K

Expedia logoExpedia● HardINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Three Expedia intern write-ups mention this task. A post from 2019 about a campus visit says the first technical interview asked for it right after a plain list reversal. An entry listed in 2023, about two on-campus rounds, includes an item whose name matches the well-known version of this task. A post from 2018 adds it to a closing set of extra links that came up for the writer or friends, without saying who got it.

None of them gives examples or limits. They also point to two versions that treat leftover nodes differently. The page linked in 2018 now flips a final group shorter than k, while the well-known version that matches the 2023 entry's name leaves it alone. Here, that short final group keeps its order. A list has 1 to 1000 nodes, k is at least 1 and at most the list length, and each value is a whole number from -1000 to 1000.

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

head points to the start of a one-way linked list, and k is a whole number, at least 1. Starting from head, cut the list into back-to-back groups of k nodes. Flip the order of the nodes inside each full group, keep the groups in their original order, and return the node that now starts the list.

When the length cannot be split evenly into groups of k, the final group is shorter than k. Do not change the order of that final group.

Function

reverseKGroup(head: ListNode, k: int) → ListNode

Examples

Example 1

head = [10,20,30,40,50,60,70,80]k = 3return = [30,20,10,60,50,40,70,80]
head
1020304050607080
→
return
3020106050407080
Moved or new

The first two groups of 3 are 10, 20, 30 and 40, 50, 60. Each is reversed, giving 30, 20, 10 and 60, 50, 40. The last group, 70, 80, has only 2 nodes, fewer than 3, so it stays as it is.

Example 2

head = [5,1,8,2]k = 2return = [1,5,2,8]
head
5182
→
return
1528
Moved or new

The 4 nodes split into two full groups of 2: 5, 1 and 8, 2. Reversing each gives 1, 5 and 2, 8. Nothing is left over.

Example 3

head = [6,-2,3]k = 3return = [3,-2,6]
head
6-23
→
return
3-26
Moved or new

k equals the length of the list, so the whole list is one group and is reversed.

Constraints

  • 1 <= n <= 1000, where n is the number of nodes.
  • 1 <= k <= n
  • Every node value is between -1000 and 1000.
  • 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
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Reverse Nodes in K-GroupAmazon · ONSITE INTERVIEW
  • Merge K Sorted Linked ListsThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Merge K Sorted ListsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Reverse Nodes in k-GroupMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Merge K Sorted ListsSkydio · ONSITE INTERVIEWSkydio interview questions
  • Merge K Sorted Linked Lists Into OneCapital One · ONSITE INTERVIEWCapital One interview questions
  • Sorted Doubly Linked List to Balanced BST In PlaceSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Merge K Sorted Linked ListsBharatPe · PHONE SCREEN
  • Reverse Nodes in K-GroupByteDance · PHONE SCREENByteDance interview questions
  • Reverse a Linked ListCisco · PHONE SCREENCisco interview questions

Interview reports that mention this question

  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 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 SWE Intern Final Round: 126 Experiences (Part 1 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 ListNode reverseKGroup(ListNode head, int k) {
        // Write your code here.
    }
}
Checking account…