File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-02 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ## Problem Description
2+
3+ Hossam woke up bored, so he decided to create an interesting array with his friend Hazem.
4+
5+ You are given an array of ` n ` positive integers
6+ ` a1, a2, ..., an ` .
7+
8+ Hossam will choose a number ` ai ` and Hazem will choose a number ` aj ` .
9+
10+ Your task is to count the number of index pairs ` (i, j) ` such that:
11+
12+ - ` 1 ≤ i, j ≤ n `
13+ - ` i ≠ j `
14+ - The absolute difference ` |ai − aj| ` is equal to the ** maximum absolute difference** over all pairs in the array
15+
16+ ---
17+
18+ ## Input Format
19+
20+ - The first line contains a single integer ` t ` — the number of test cases.
21+ - For each test case:
22+ - The first line contains an integer ` n `
23+ - The second line contains ` n ` integers ` a1, a2, ..., an `
24+
25+ ---
26+
27+ ## Output Format
28+
29+ - For each test case, print a single integer — the number of valid pairs ` (i, j) ` .
30+
31+ ---
32+
33+ ## Constraints
34+
35+ - ` 1 ≤ t ≤ 100 `
36+ - ` 2 ≤ n ≤ 100000 `
37+ - ` 1 ≤ ai ≤ 100000 `
38+ - The sum of ` n ` over all test cases does not exceed ` 100000 `
39+
40+ ---
41+
42+
43+ ## Sample Input
44+
45+ ```
46+ 2
47+ 5
48+ 6 2 3 8 1
49+ 6
50+ 7 2 8 3 2 10
51+ ```
52+ ---
53+
54+ ## Output
55+
56+ ```
57+ 2
58+ 4
59+ ```
60+
61+ [ PROBLEM LINK] ( https://codeforces.com/problemset/problem/1771/A )
62+
You can’t perform that action at this time.
0 commit comments