Next Heavier Tote on a Circular Sorting Carousel
Last updated: November 29, 2026
Quick Overview
Totes ride a circular carousel in a fixed order with weights w[0..n-1]. For each tote, return the weight of the first strictly heavier tote encountered moving forward around the loop, or -1 if none exists.
Amazon
November 29, 20260
0
0 solved
Totes ride a circular carousel in a fixed order with weights w[0..n-1]. For each tote, return the weight of the first strictly heavier tote encountered moving forward around the loop, or -1 if none exists.
An Amazon phone screen variation on next greater element that tests whether you can handle circular arrays without copying them. The interviewer expects two passes over indices modulo n with a monotonic stack.
What the Interviewer Expects
- Iterates 2n times using i % n
- Pushes indices only during the first pass
- Resolves waiting indices when a heavier tote appears
- Leaves -1 for the global maximum
- Gives O(n) time
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
- Return the distance in positions instead of the weight.
- What if the carousel can rotate both ways?
- Handle updates to tote weights online.
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: list w of integers, length up to 10^4. Output: list res where res[i] is the next strictly greater value going forward circularly, or -1....
High-Level Design
In a straight line we would scan once with a decreasing stack of indices. On a circle, a tote near the end may find its answer near the start, so scan the sequence twice by iterating i from 0 to 2n - ...