Trains the technique from
LeetCode 496Next Greater Element IThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
An auction house sold its lots one after another and recorded the hammer price of each lot in sales, in the order the lots went under the hammer. No two lots fetched the same price.
A dealer kept a watchlist of prices, each of which is one of the recorded prices. For every price on the watchlist, the dealer wants to know the price of the first lot sold after that lot which fetched a strictly higher price. When no later lot beat it, the answer for that price is -1.
Return the answers in the same order as watchlist.
Example 1
The lot that fetched 9 was followed by 5, which is lower, then by 12, which beats it. The lot that fetched 3 was beaten right away by 9.
Example 2
After the lot at 2 came 5, which is higher. Nothing after the opening lot at 10 beat it, so its answer is -1. After 5 came 7.
Example 3
The lot at 9 sold before the watched lot, so it does not count; the only later lot fetched 1.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def next_higher_sale(watchlist: list[int], sales: list[int]) -> list[int]:public int[] nextHigherSale(int[] watchlist, int[] sales)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.