Sequence Picker Tasks So No Two Adjacent Picks Share a Zone
Last updated: November 29, 2026
Quick Overview
A picker's task list is a string where each letter is a warehouse zone. Rearrange it so no two consecutive tasks are in the same zone and return any valid ordering, or an empty string if impossible.
Amazon
November 29, 20260
0
0 solved
A picker's task list is a string where each letter is a warehouse zone. Rearrange it so no two consecutive tasks are in the same zone and return any valid ordering, or an empty string if impossible.
An Amazon technical screen heap question framed around reducing congestion in pick paths. Interviewers check that you spot the feasibility bound quickly and use a max-heap greedy that always places the most frequent remaining zone that is allowed.
What the Interviewer Expects
- State the impossibility condition: max count > (n + 1) // 2
- Use a max-heap of (count, zone) pairs
- Hold back the previously placed zone for one step
- Explain why picking the most frequent allowed zone never paints you into a corner
- Offer the O(n) even-index filling alternative
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you generalize to require at least k positions between equal zones?
- Can you do it in O(n) without a heap?
- How would you produce the lexicographically smallest valid ordering?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a string s of uppercase or lowercase letters, length up to about 10^5. Output: a permutation of s with no equal adjacent characters, or '' if none exists....
High-Level Design
Count each zone. If the most common zone appears more than (n + 1) // 2 times, there are not enough separators, so return ''. Otherwise use a max-heap keyed on remaining count. Each step pop the top z...