X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Is Square
Easy Accuracy: 30.91% Submissions: 4198 Points: 2

Given four different points in space. Find whether these points can form a square or not.

 

Example 1:

Input:
x1 = 20, y1 = 10, x2 = 10, y2 = 20, 
x3 = 20, y3 = 20, x4 = 10, y4 = 10 
Output:
Yes
Explanation:
The points (20,10), (10,20), (20,20),
(10,10) forms a square.

Example 2:

Input:
x1 = 2, y1 = 1, x2 = 10, y2 = 20, 
x3 = 5, y3 = 6, x4 = 10, y4 = 10 
Output:
No
Explanation:
The points (2,1), (10,20), (5,6),
(10,10) doesn't form a square.

 

Your Task:
You don't need to read input or print anything. Your task is to complete the function isSquare() which takes 8 Integers x1, y1, x2, y2, x3, y3, x4, and y4 as input and returns whether these points form a square.

 

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

 

Constraints:
-103 ≤ x1, y1, x2, y2, x3, y3, x4, y4 ≤ 103

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Is Square

Output Window