Please help in this interview problem

Правка en4, от saint_coder, 2019-06-19 11:27:07

I thought of a solution but I have a doubt if my solution will work.

Please tell your solution of solving it, also a little analysis of the time complexity(if you have time)

Here's the Problem:

Given two arrays of integers A and B of size N each, where each pair (A[i], B[i]) for represents a unique point (x, y) in the 2D Cartesian plane.

Find and return the number of unordered quadruplet (i, j, k, l) such that (A[i], B[i]), (A[j], B[j]), (A[k], B[k]) and (A[l], B[l]) form a rectangle with the rectangle having all the sides parallel to either x-axis or y-axis.

Input Format The first argument given is the integer array A. The second argument given is the integer array 8.

Output Format Return the number of unordered quadruplets that form a rectangle.

Constraints

1<=N<=2000

1<=A[i],B[i]<=10^9

For Example:

Input 1: A=[1,1,2,2] B=[1,2,1,2]

Output 1: 1

Input 2: A=[1,1,2,2,3,3] B=[1,2,1,2,1,2]

Output 2: 3

Теги #interview, #problem, #geometry

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский saint_coder 2019-06-19 11:27:07 2 Tiny change: 'straints\n1<=N<=20' -> 'straints\n\n1<=N<=20'
en3 Английский saint_coder 2019-06-19 11:22:41 770 Tiny change: '=N<=2000\n1<=A[i],' -> '=N<=2000\n\n1<=A[i],'
en2 Английский saint_coder 2019-06-19 09:32:49 66
en1 Английский saint_coder 2019-06-19 09:31:10 268 Initial revision (published)