Alternate Divisible Nodes After Reversing a Prefix
Updated
Problem statement
You are given a singly linked list head, a positive integer divisor, and an integer k.
- Reverse the first
knodes. - From that resulting order, form two stable groups: values divisible by
divisorand values not divisible by it. - 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) → ListNodeExamples
Example 1
head = [1,2,3,4,5,6]divisor = 2k = 4return = [4,3,2,1,6,5]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]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)