You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hossam woke up bored, so he decided to create an interesting array with his friend Hazem.
10
+
11
+
Now, they have an array a
12
+
of n positive integers, Hossam will choose a number ai and Hazem will choose a number aj
13
+
14
+
.
15
+
16
+
Count the number of interesting pairs (ai,aj)
17
+
18
+
that meet all the following conditions:
19
+
20
+
1≤i,j≤n
21
+
i≠j
22
+
The absolute difference |ai−aj| must be equal to the maximum absolute difference over all the pairs in the array. More formally, |ai−aj|=max1≤p,q≤n|ap−aq|.
23
+
24
+
APPROACH:
25
+
just count the freq of max &min elements and by basic combinotorics we get ans 2*fmax*fmin
26
+
but if all elements are equal i.e fmax ==fmin then ans is n*(n-1) by basic combinototics too.
0 commit comments