Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6564 |

@blackshadows | 6400 |

@mb1973 | 5785 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4639 |

@sanjay05 | 3762 |

@mantu_singh | 3712 |

@gfgaccount | 3627 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@yaswanthero123 | 625 |

@vikash619 | 611 |

@venkat11803610 | 501 |

@roshan13ar | 396 |

@DevangSingh | 379 |

@ravi11815721 | 312 |

@hrishipangavhane | 286 |

@aryanjain85297 | 280 |

@kommaraju11806903 | 277 |

@infosumitraut | 272 |

@ankitsharma5422 | 256 |

Complete Leaderboard |

In a given cartesian plane, there are **N** points. We need to find the Number of Pairs of points(**A, B**) such that

- Point A and Point B do not coincide.
- Manhattan Distance and the Euclidean Distance between the points should be equal.

**Note:** Pair of 2 points(A,B) is considered same as Pair of 2 points(B ,A).

Manhattan Distance = |x2-x1|+|y2-y1|

Euclidean Distance = ((x2-x1)^2 + (y2-y1)^2)^0.5, where points are (x1,y1) and (x2,y2).

**Example 1:**

Input:N =2X ={1, 7}Y ={1, 5}Output:0Explanation:None of the pairs of points have equal Manhatten and Euclidean distance.

**Example 2:**

Input:N =3X ={1, 2, 1}Y ={2, 3, 3}Output:2Explanation:The pairs {(1,2), (1,3)}, and {(1,3), (2,3)} have equal Manhatten and Euclidean distance.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **numOfPairs()** which takes an Integer N and two arrays X, and Y of length N as input and returns the number of pairs with equal Manhattan and Euclidean Distance. (X[i], Y[i]) denotes a point.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 <= N <= 10^{5}

-10^9 <= X[i], Y[i] <= 10^9

Login to report an issue on this page.

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

YesLoading...

Pairs of Non Coinciding Points

...