Buy Volumes (Order Books :)
Learn this problemProblem statement
Amazon Books is a retail store that sells the newly launched novel "The Story of Amazon". The novel is divided into volumes numbered from 1 to n and unfortunately, all the volumes are currently out of stock.
The Amazon team announced that starting today, they will bring exactly one volume of "The Story of Amazon" in stock each of the next n days. On the nth day, all volumes will be there. Being an impatient bookworm, each day you will purchase the maximum number of volumes you can such that:
Note: For the ith volume of the novel, all the volumes such that j < i are its prequels.
Determine the volumes you would purchase each day. You should return an array of n arrays where the ith array contains:
Function
buyVolumes(volumes: int[]) → int[][]
Complete the function buyVolumes in the editor below.
buyVolumes has the following parameter:
int volumes[n]: an array of integers where the ith integer denotes the volume that is in stock on the ith day
Returns
int[n][n]: a 2d array of integers where the ith array denotes the volumes purchased on the ith day
𓈒𓇼 ࣪ 𓈒 Manyy Manyyy thanks to da best aikay and kl~~!⭒𓆡 ⭒ 🫧
Examples
Example 1
volumes = [2, 1, 4, 3]return = [[-1], [1, 2], [-1], [3, 4]]
Example 2
volumes = [1, 4, 3, 2, 5]return = [[1], [-1], [-1], [2, 3, 4], [5]]
- Day 1, Volume 1 is released. Purchase volume 1. answer[0] = [1]
- Day 2, Volume 4 is released. No volumes are purchased since you do not own all volumes 1 and 3. answer[1] = [-1]
- Day 3, Volume 3 is released. No volumes are purchased since you do not own volume 2. answer[2] = [-1]
- Day 4, Volume 2 is released. Purchase all three volumes. answer[3] = [2, 3, 4]
- Day 5, Volume 5 is released. Purchase volume 5. answer[4] = [5]
Example 3
volumes = [1, 2, 3]return = [[1], [2], [3]]Constraints
More Amazon problems
- Drone Delivery RouteOA · Seen Aug 2026
- Package Dependency OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Unfulfilled Customers by Inventory PriorityOA · Seen Aug 2026
- Calculate Beauty ValuesOA · Seen Aug 2026
- Maximize Distance to the Closest Occupied SeatONSITE INTERVIEW · Seen Aug 2026
- Package Delivery SystemOA · Seen Aug 2026
- Select Least Resource TasksOA · Seen Aug 2026
- Maximum Length-K Window Sum over Sparse SegmentsOA · Seen Aug 2026