Skip to content

Commit 326c4b3

Browse files
authored
Merge pull request #279 from arnavsingh010/Arnav
solved Day-02 Q1
2 parents af70d18 + 65a0ca1 commit 326c4b3

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: Solution1","url":"\\\\wsl.localhost\\Ubuntu\\home\\arnav\\cp\\CP-Chronicles\\Problems\\Mathematics\\Day-02\\sol\\Arnav_Singh\\Solution1.cpp","tests":[{"id":1766899575930,"input":"2\n5\n6 2 3 8 1","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"\\\\wsl.localhost\\Ubuntu\\home\\arnav\\cp\\CP-Chronicles\\Problems\\Mathematics\\Day-02\\sol\\Arnav_Singh\\Solution1.cpp","group":"local","local":true}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main() {
5+
int t;
6+
cin >> t;
7+
while(t--) {
8+
int n;
9+
cin>>n;
10+
long long a[n];
11+
for (int i = 0; i < n; ++i) {
12+
cin >>a[i];
13+
}
14+
sort(a,a+n);
15+
long long cnt_s=0;
16+
for (int i = 0; i < n; ++i) {
17+
if(a[i]==a[0]){
18+
cnt_s++;
19+
}
20+
else{
21+
break;
22+
}
23+
}
24+
long long cnt_l=0;
25+
for (int i = n-1; i >=0 ; --i) {
26+
if(a[i]==a[n-1]){
27+
cnt_l++;
28+
}
29+
else{
30+
break;
31+
}
32+
}
33+
if(cnt_s==n){
34+
cout << 1LL*(n)*(n-1) <<'\n';
35+
}
36+
else{
37+
cout <<2LL*(cnt_s)*(cnt_l)<<'\n';
38+
}
39+
}
40+
41+
return 0;
42+
}
43+
//time complexity O(nlogn)
44+
//https://codeforces.com/problemset/submission/1771/355443489
138 KB
Binary file not shown.

0 commit comments

Comments
 (0)