Next Larger on the Right
Easy · Next Larger on the Right
You are given a list `line` of distinct non-negative integers and a list `queries` of distinct numbers, each of which appears in `line`. For each query, find where it sits in `line` and look to the right: the first number larger than the query is its answer. If no larger number follows, the answer is -1. Return the answers in the same order as the queries. The O(len(`queries`) · len(`line`)) approach is the obvious one; try for O(len(`queries`) + len(`line`)).…
Solve the problem →