Count Perfect Stamp Packagings

Asked at Amazon · Coding Questions · Difficulty: Medium

Parcels are labelled left to right with one of five stamps (indices 1..5). A packaging is *perfect* if for every `i > 0`: when `prices[i] > prices[i-1]` then `stamp[i] > stamp[i-1]`; when `prices[i] < prices[i-1]` then `stamp[i] < stamp[i-1]`; when `prices[i] == prices[i-1]` then `stamp[i] != stamp[i-1]`. Count the perfect packagings modulo `1_000_000_007`.

Loading the problem…