The problem, in one line. For each query number, return the length of the shortest interval containing it, or -1 if none does. LeetCode 1851.
The tell. Many intervals, many point questions, and a “smallest” among those covering the point. Sort both lists, sweep once, and keep the live candidates in a min-heap.
Included with a plan
This solution is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.