Trains the technique from
LeetCode 526Beautiful ArrangementThis 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 stockroom has size shelves, numbered 1 through size, and size crates, also numbered 1 through size. Exactly one crate goes on each shelf.
A crate is allowed on a shelf only when the two numbers divide one another: the crate number is a multiple of the shelf number, or the shelf number is a multiple of the crate number. Either direction is fine.
Return how many different complete placements satisfy that rule. Two placements differ when some shelf holds a different crate.
Example 1
Writing a placement as the crate on shelf 1, shelf 2, shelf 3, the allowed placements are (1, 2, 3), (2, 1, 3) and (3, 2, 1). Shelf 1 accepts any crate, and shelf 3 accepts only crate 1 or crate 3.
Example 2
Eight complete placements obey the rule, one of them being (2, 4, 3, 1): crate 2 on shelf 1, crate 4 on shelf 2, crate 3 on shelf 3 and crate 1 on shelf 4.
Example 3
Ten placements obey the rule. Crate 5 can only sit on shelf 1 or shelf 5, and crate 3 can only sit on shelf 1 or shelf 3.
Example 4
Thirty-six placements obey the rule, for instance (6, 2, 3, 4, 5, 1) and (1, 6, 3, 4, 5, 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 count_placements(size: int) -> int:public int countPlacements(int size)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.