Buy Volumes in Prerequisite Order

Asked at Amazon · Coding Questions · Difficulty: Medium

A novel series has volumes numbered `1..n`, all out of stock. Each day one volume comes into stock: `volumes[i]` is the volume that arrives on day `i`. Each day you buy as many volumes as possible, but you can buy a volume only if you do not own it yet and you already own every volume numbered before it (volume `v` requires owning `1..v-1`). Return an array of `n` lists: the volumes bought on each day in ascending order, or `[-1]` if none bought that day.

Loading the problem…