Trains the technique from
LeetCode 367Valid Perfect SquareThis 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 depot has crates identical crates and wants to set them out as one solid square block on
the floor: the same number of rows as columns, every position filled, and not a single crate
left over or borrowed.
Given crates, return true when a whole number of rows exists that makes such a block, and
false when it does not.
Settle it with arithmetic on integers. Do not reach for a square-root or power routine from the standard library, and do not float the count through a fractional type on the way.
Example 1
899 rows of 899 crates each use exactly 808201 crates.
Example 2
A 3 by 3 block uses 9 and leaves 2 spare, and a 4 by 4 block would need 5 crates more, so no square block fits 11 exactly.
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 fits_square_block(crates: int) -> bool:public boolean fitsSquareBlock(int crates)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.