Trains the technique from
LeetCode 274H-IndexThis 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 bakery keeps one entry per cake design on its menu. orders[i] is how many times design i was ordered over the past season.
The owner grades the whole menu with a single number called the staple score: the largest value s for which the menu contains s or more designs that were each ordered s or more times. A menu where nothing was ever ordered scores 0.
Given orders, return the staple score. The entries arrive in menu order, which has nothing to do with popularity.
Example 1
Designs with 7, 4 and 4 orders give three designs at three or more orders each, so 3 works. A score of 4 would need four designs at four or more orders, and only three designs reach four.
Example 2
All four designs were ordered at least four times, so 4 works. The menu only has four designs, so no larger score is possible.
Example 3
Every one of the six designs was ordered at least twice, so 2 works. A score of 3 would need three designs at three or more orders, and only the two designs with 6 orders qualify.
Example 4
The single design was ordered five times, which is at least one, so 1 works. A one-design menu can never support a score of 2.
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 staple_score(orders: list[int]) -> int:public int stapleScore(int[] orders)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.