Buy Volumes (Order Books :)
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:
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~~!βπ‘ β π«§
1Example 1

2Example 2
- 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]
3Example 3
Constraints
Limits and guarantees your solution can rely on.