Next Greater Element I
Recognize the pattern
Brute force idea
The naive version of Next Greater Element I sounds like this: For each element in nums1, find it in nums2, then scan right for a larger one. The waste is re-scanning the same portion of nums2 for elements that share the same 'next greater.'. That direct path helps you understand the question, but it tends to treat every possibility as brand new instead of learning from earlier steps.
Better approach
The real unlock in Next Greater Element I comes when you notice this: Process nums2 right-to-left (or left-to-right with a stack): build a map of each element to its next greater element. A monotonic decreasing stack naturally identifies the next greater element for each value in. Instead of recomputing the world every time, you preserve just enough context to let the next decision become obvious.
Key invariant
The compass for Next Greater Element I is this: The stack holds elements that haven't yet found their next greater element, in decreasing order. When a new element is larger than the stack top, it's the 'next greater' for everything it displaces. As long as that statement keeps holding, you can trust the steps built on top of it.
Watch out for
A common way to get lost in Next Greater Element I is this: Trying to solve it per-query from nums1 instead of precomputing the answer for all of nums2 first. The map-based approach answers every query in after one pass. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.