Distance between 2 points
School Accuracy: 51.5% Submissions: 1493 Points: 0

Given coordinates of 2 points on a cartesian plane, find the distance between them rounded up to nearest integer.

Example 1:

Input: 0 0 2 -2
Output: 3
Explanation: Distance between (0, 0) 
and (2, -2) is 3.

Example 2:

Input: -20 23 -15 68
Output: 45
Explanation: Distance between (-20, 23) 
and (-15, 68) is 45.

Your Task:
You don't need to read or print anything. Your task is to complete the function distance() which takes x1, y1, x2 and y2 as input parameter and returns the distance between the given two points.

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

Constraints:
-1000 <= x1, y1, x2, y2 <= 1000

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


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.

Distance between 2 points

Output Window