Trains the technique from
LeetCode 593Valid 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 land surveyor has hammered four pegs into a field and recorded each one as a coordinate pair [x, y] on the site grid. The pegs are handed to you as p1, p2, p3 and p4 in no particular order: the recording sequence says nothing about how the pegs sit relative to one another, so the corners of the plot may appear in any of the four positions.
Decide whether the four pegs are exactly the four corners of a square whose side length is greater than zero. All four sides must have the same length and all four corners must be right angles. Pegs that coincide, or that all lie on one straight line, cannot mark such a square.
Return true when the pegs mark a square plot and false otherwise.
Example 1
Walking the pegs as `[1, 1]`, `[6, 1]`, `[6, 6]`, `[1, 6]` gives four sides of length 5 that meet at four right angles, so the pegs mark a square of side 5.
Example 2
Three of the pegs sit on the vertical line `x = 2`, so no arrangement of the four gives a shape with four right angles.
Example 3
Walking the pegs as `[3, 0]`, `[0, 3]`, `[-3, 0]`, `[0, -3]` gives four sides that each span 3 across and 3 up or down, and each corner turns through a right angle. A square does not have to be lined up with the grid axes.
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_square_plot(p1: list[int], p2: list[int], p3: list[int], p4: list[int]) -> bool:public boolean isSquarePlot(int[] p1, int[] p2, int[] p3, int[] p4)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.