FastPrepReverse Nodes in k-Group
Problems/Reverse Nodes in k-Group

Reverse Nodes in k-Group

Microsoft logoMicrosoft● HardINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two reviews of Microsoft software engineering internship interviews both list a question about reversing a linked list in blocks of k nodes. Neither review gives more detail.

The reports do not say what happens to the nodes at the end that do not fill a group, or give any limits. Here, a last group with fewer than k nodes keeps its order, and k is never larger than the list.

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

You are given the head of a singly linked list and a positive integer k. Split the list into groups of k nodes, starting from the head, and reverse the order of the nodes inside each full group. Return the head of the changed list.

If the last group has fewer than k nodes, leave those nodes in their original order.

Follow-up: can you do it by changing the links in place, using only O(1) extra memory?

Function

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

Examples

Example 1

head = [1,2,3,4,5,6,7,8]k = 3return = [3,2,1,6,5,4,7,8]
head
12345678
→
return
32165478
Moved or new

The first two groups of 3 are 1, 2, 3 and 4, 5, 6; they become 3, 2, 1 and 6, 5, 4. Only 7, 8 is left, which is fewer than 3 nodes, so it stays as it is.

Example 2

head = [5,9,2]k = 1return = [5,9,2]
head
592
→
return
592

A group of one node reversed is the same node, so the list does not change.

Example 3

head = [4,3,2,1]k = 4return = [1,2,3,4]
head
4321
→
return
1234
Moved or new

The whole list is exactly one group of 4, so the whole list is reversed.

Constraints

  • The number of nodes n is in the range [1, 5000].
  • 0 <= Node.val <= 1000
  • 1 <= k <= n

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

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
  • Merge K Sorted ListsSkydio · ONSITE INTERVIEWSkydio interview questions
  • Reverse a Linked List in Groups of KExpedia · ONSITE INTERVIEWExpedia 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

  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft 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…