FastPrepAlternate Divisible Nodes After Reversing a Prefix
Problems/Alternate Divisible Nodes After Reversing a Prefix

Alternate Divisible Nodes After Reversing a Prefix

Adobe logoAdobe● MediumFULLTIMEOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source reports alternating divisible and nondivisible linked-list elements with the first k elements reversed. It omits the divisor, operation order, starting group and leftover rule. This practice version authors those choices explicitly, preserves within-group order after prefix reversal, and adds bounds and the interface.

You are given a singly linked list head, a positive integer divisor, and an integer k.

  1. Reverse the first k nodes.
  2. From that resulting order, form two stable groups: values divisible by divisor and values not divisible by it.
  3. Alternate the groups, starting with a divisible value. When either group is empty, append every remaining node from the other group in order.

Return the new head, reusing the input nodes. Zero and negative multiples count as divisible. A few temporary dummy nodes are allowed. Examples serialize a list as an array of its values.

Function

rearrangeDivisible(head: ListNode, divisor: int, k: int) → ListNode

Examples

Example 1

head = [1,2,3,4,5,6]divisor = 2k = 4return = [4,3,2,1,6,5]
head
123456
→
return
432165
Moved or new

Reverse the first four nodes to obtain [4,3,2,1,5,6]. The stable groups are [4,2,6] and [3,1,5]. Alternating them gives [4,3,2,1,6,5].

Example 2

head = [1,2,3]divisor = 5k = 0return = [1,2,3]
head
123
→
return
123

The prefix is empty and no value is divisible by 5. Append the whole nondivisible group unchanged.

Constraints

  • 0 <= head.length <= 2000
  • -1000000000 <= head[i] <= 1000000000
  • 1 <= divisor <= 1000000000
  • 0 <= k <= 2000
  • k <= head.length

Source note: Screenshots of public Reddit comments describing the reported Adobe OA task and any included author clarification. The practice version adds the details stated in the source note.

More Adobe Online Assessment questions

  • Base Unit ConversionsOA · Seen Nov 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Top-Funded Villages and ProjectsOA · Seen Aug 2026
  • Count Parent Nodes With a Target SumOA · Seen Aug 2026
  • Largest Binary Number by ConcatenationOA · Seen Aug 2026
  • Count Events by CategoryOA · Seen Aug 2026
  • Graph M-ColoringOA · Seen Aug 2026
  • Hall of Shifting TilesOA · Seen Aug 2026
  • K-th Ancestor Subtree Preorder QueryOA · Seen Aug 2026
  • Maze ReachabilityOA · Seen Aug 2026

Similar questions at other companies

  • LRU CacheTypeSafe AI · OA
  • Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
  • Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Largest Microorganism After ConsumptionOpenAI · OAOpenAI interview questions
  • Buffet Day GainsUpstart · OAUpstart interview questions
  • Chain MergeRubrik · OARubrik interview questions
  • LRU Page FaultsExpedia · OAExpedia interview questions
  • LFU CacheSnowflake · OA · ONSITE INTERVIEWSnowflake interview questions
  • LFU CacheArista Networks · OAArista Networks interview questions
  • Find the Intersection Node of Two Linked ListsConcentric AI · OAConcentric AI interview questions

Adobe interview experiences

  • Adobe New Grad OA: Unit Conversion and Code Review: 1 Experience
  • 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
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 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 rearrangeDivisible(ListNode head, int divisor, int k) {
        // Write your solution here
    }
}
Checking account…