All problems
0437MediumMathTwo PointersBinary Search

Two Square Courts From One Delivery

Tracked in this browser only
Write code

Trains the technique from

LeetCode 633Sum of Square Numbers

This 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 groundworks firm has taken delivery of exactly c identical square slabs and wants to lay two square courts with them, using up every slab and cutting none.

A court is a solid square block, so a court whose side measures s slabs swallows s * s slabs. A side of zero slabs is allowed and simply means that court is not laid at all.

Return true if some choice of the two side lengths uses the delivery up exactly, and false if some slabs would always be left over.

Examples

Example 1

Input
c = 8
Output
true

Two courts of side two each swallow four slabs, which accounts for all eight.

Example 2

Input
c = 6
Output
false

Every pairing of side lengths either leaves slabs in the yard or calls for more than were delivered.

Example 3

Input
c = 26
Output
true

A court of side five swallows twenty-five slabs and a court of side one swallows the last slab.

Example 4

Input
c = 0
Output
true

Nothing was delivered, and two courts of side zero use up nothing.

Constraints

  • 0 <= c <= 2^31 - 1

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def judge_square_sum(c: int) -> bool:
Java
public boolean judgeSquareSum(int c)
September 7
Apply