FastPrepReverse Linked-List Groups of Alternating Sizes
Problems/Reverse Linked-List Groups of Alternating Sizes

Reverse Linked-List Groups of Alternating Sizes

Adobe logoAdobe● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You reverse a linked list in groups whose size switches back and forth between two numbers, x and then y. An Adobe senior software engineer report (Noida, about seven years of experience) opens its first coding round with the well-known exercise of reversing a list k nodes at a time. The interviewer changed it so that the group size takes turns between two values. The author adds that the questions were changed a little because of an NDA. No limits, examples or rule for an incomplete group at the end are given.

We chose these rules. An incomplete last group keeps its original order, as in the classic version. The list has at most 2000 nodes, with values from -1000 to 1000. Both sizes are from 1 to 2000. We wrote new examples.

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

You are given the head of a singly linked list and two group sizes x and y. Walk the list from the head and cut it into consecutive groups whose sizes take turns: the first group has x nodes, the second y, the third x, the fourth y, and so on.

Reverse the order of the nodes inside every full group. If the last group has fewer nodes than its size calls for, leave it in its original order. Return the head of the resulting list.

Function

reverseAlternatingGroups(head: ListNode, x: int, y: int) → ListNode

Examples

Example 1

head = [4,9,2,7,5,1,8]x = 2y = 3return = [9,4,5,7,2,8,1]
head
4927518
→
return
9457281
Moved or new

The groups have sizes 2, 3, 2: [4, 9], [2, 7, 5] and [1, 8]. All three are full, so each is reversed: [9, 4], [5, 7, 2], [8, 1].

Example 2

head = [3,6,1,8,2,5,7]x = 3y = 2return = [1,6,3,2,8,5,7]
head
3618257
→
return
1632857
Moved or new

The first group [3, 6, 1] becomes [1, 6, 3] and the second [8, 2] becomes [2, 8]. The third group should have 3 nodes but only [5, 7] are left, so it stays as it is.

Example 3

head = [10,20]x = 5y = 1return = [10,20]
head
1020
→
return
1020

The first group needs 5 nodes but the list has only 2, so nothing is reversed.

Constraints

  • The list has between 0 and 2000 nodes.
  • -1000 <= node.val <= 1000
  • 1 <= x <= 2000
  • 1 <= y <= 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

  • Greedy Person-Cake Matching DistanceSnowflake · PHONE SCREENSnowflake interview questions
  • Least Frequently Used CacheNVIDIA · PHONE SCREENNVIDIA interview questions
  • Checkpointed Dynamic SequenceOpenAI · PHONE SCREENOpenAI interview questions
  • Merge k Sorted ListsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • LRU Cache with Expiring EntriesPaytm · PHONE SCREENPaytm interview questions
  • LFU CacheFreshworks · PHONE SCREENFreshworks interview questions
  • Merge K Sorted Linked ListsBharatPe · PHONE SCREEN
  • Reverse Nodes in K-GroupByteDance · PHONE SCREENByteDance interview questions
  • LFU Cache with LRU Tie-BreakingRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Merge k Sorted ListsOracle · PHONE SCREENOracle interview questions

Interview reports that mention this question

  • Adobe SDE and Senior SWE Interviews: 9 Experiences (Part 3 of 6)
  • Adobe Experienced Hire Interviews: 55 Experiences (Part 1 of 6)

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 New Grad MTS Interview Questions: 7 Experiences
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 reverseAlternatingGroups(ListNode head, int x, int y) {
        // Write your code here.
    }
}
Checking account…