Trains the technique from
LeetCode 846Hand of StraightsThis 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 trolley holds loose journal booklets. You are given hand, where hand[i] is the issue number printed on the i-th booklet; the trolley may well hold several booklets bearing the same issue number.
The booklets have to go out on display in runs. A run is a shelf holding exactly groupSize booklets whose issue numbers are groupSize consecutive whole numbers, with each of those numbers appearing on exactly one booklet of that run.
Return true if every booklet on the trolley can be placed on some run, each booklet used once and no booklet left over, and false otherwise.
Example 1
The five booklets carry the consecutive issue numbers 6 through 10, which is exactly one run of five.
Example 2
Two runs of three can be filled, each holding issues 4, 5 and 6, and that uses all six booklets.
Example 3
Two runs of two are needed. One of them must hold the pair 4 and 5, which leaves the booklets 4 and 6, and those issue numbers are not consecutive.
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 is_n_straight_hand(hand: list[int], groupSize: int) -> bool:public boolean isNStraightHand(int[] hand, int groupSize)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.