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

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You reverse a singly linked list k nodes at a time, and a shorter last group is reversed too. An April 2022 post is by a 2021 graduate who applied through a job site for an MTS-1 opening at Adobe in India and was rejected. It gives this as the first question of the earliest live interview, held after a 90-minute online test. The post states the task in one line and says the change had to be made in place. It shows one sample of eight nodes with k = 3, in which the last two nodes are swapped too.

Our rules follow that sample, so a shorter last group is reversed. This differs from the better-known version that leaves it alone. We chose these limits: 1 to 2000 nodes, with values from -1000 to 1000, and k from 1 to 2000. We wrote new examples. The tests see only the returned list, so they cannot tell moved nodes from copied ones. The editorial's final method works in place.

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

You are given the head of a singly linked list and an integer k. Starting from the head, cut the list into groups of k nodes; the last group may have fewer than k nodes.

Reverse the order of the nodes inside every group, including a shorter last group, keep the groups in their original order, and return the head of the resulting list. Rearrange the existing nodes instead of creating new ones.

Function

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

Examples

Example 1

head = [5,3,9,1,4,8,2]k = 3return = [9,3,5,8,4,1,2]
head
5391482
→
return
9358412
Moved or new

The groups are [5, 3, 9], [1, 4, 8] and the shorter last group [2]. Each is reversed: [9, 3, 5], [8, 4, 1], [2].

Example 2

head = [10,20,30,40,50]k = 2return = [20,10,40,30,50]
head
1020304050
→
return
2010403050
Moved or new

Groups [10, 20], [30, 40] and [50] become [20, 10], [40, 30] and [50].

Example 3

head = [6,7,8]k = 5return = [8,7,6]
head
678
→
return
876
Moved or new

k is larger than the list, so the whole list is one short group, and it is reversed too.

Constraints

  • The list has between 1 and 2000 nodes.
  • -1000 <= node.val <= 1000
  • 1 <= k <= 2000

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • LRU CacheGimlet Labs · PHONE SCREEN
  • LRU CacheBNSF Railway · PHONE SCREENBNSF Railway interview questions
  • Max Frequency TrackerProcol · PHONE SCREEN
  • Balanced Session ManagerPalantir · PHONE SCREENPalantir interview questions
  • LRU Cache Operation SequenceCARS24 · PHONE SCREEN
  • LRU Key-Value Cache OperationsCohesity · PHONE SCREEN
  • Merge Timestamped Record ListsNuro · PHONE SCREENNuro interview questions
  • Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions

Interview reports that mention this question

  • Adobe New Grad MTS Interview Questions: 7 Experiences

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
  • Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)
All Adobe interview questionsSee Adobe 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 reverseInGroups(ListNode head, int k) {
        // Write your code here.
    }
}
Checking account…