Trains the technique from
LeetCode 1051Height CheckerThis 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.
A shelf holds jars whose sizes are listed in sizes, left to right. The jars are meant to stand in non-decreasing order of size.
Return how many positions on the shelf hold a jar of a different size from the one that would stand there once the jars were put in that order.
Example 1
In size order the jars would stand 1, 1, 2, 2. Every one of the four positions holds a different size from that.
Example 2
In size order the jars would run 1 up to 6. The second and third positions are the wrong way round and so are the last two.
Example 3
Every jar is the same size, so the shelf already stands in size order.
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 height_checker(sizes: list[int]) -> int:public int heightChecker(int[] sizes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.