Skip to content

Commit d53fe2d

Browse files
committed
leetcode 2697
1 parent 5098f1f commit d53fe2d

8 files changed

+216
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
long long n;
12+
cin>>n;
13+
for (long long i = 2; i * i <= n; i++)
14+
{
15+
if (n % i == 0)
16+
{
17+
long long temp = n / i;
18+
for (long long j = 2; j * j <= temp; j++)
19+
{
20+
if (temp % j == 0)
21+
{
22+
cout << 1 << endl
23+
<< i * j << endl;
24+
return 0;
25+
}
26+
}
27+
cout << 2;
28+
return 0;
29+
}
30+
}
31+
cout << 1 << endl
32+
<< 0;
33+
return 0;
34+
}
35+
int main()
36+
{
37+
int testCase=1;
38+
while(testCase--){
39+
solve();
40+
}
41+
return 0;
42+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
int n;
12+
cin >> n;
13+
14+
for (int i = 1; i <= n; i++)
15+
{
16+
cout << i * 2 << ' ';
17+
}
18+
cout << endl;
19+
return 0;
20+
}
21+
int main()
22+
{
23+
int testCase=1;
24+
cin>>testCase;
25+
while(testCase--){
26+
solve();
27+
}
28+
return 0;
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
int n;
12+
cin >> n;
13+
14+
vector<int> v(n);
15+
16+
for (int i = 0; i < n; i++)
17+
{
18+
cin >> v[i];
19+
v[i]--;
20+
}
21+
22+
vector<int> ds;
23+
24+
for (int i = 0; i < n; i++)
25+
{
26+
int d = abs(v[i] - i);
27+
if (d == 0)
28+
continue;
29+
ds.push_back(d);
30+
}
31+
32+
int ans = 1;
33+
ans = ds[0];
34+
35+
for (auto x : ds)
36+
{
37+
ans = __gcd(ans, x);
38+
}
39+
40+
cout << ans << endl;
41+
return 0;
42+
}
43+
int main()
44+
{
45+
int testCase=1;
46+
cin>>testCase;
47+
while(testCase--){
48+
solve();
49+
}
50+
return 0;
51+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
string s;
12+
cin>>s;
13+
if (s.size() % 2) {
14+
s.erase(s.begin() + s.size() / 2);
15+
}
16+
if (s != std::string(s.size(), s[0])) {
17+
cout << "YES\n";
18+
} else {
19+
cout << "NO\n";
20+
}
21+
return 0;
22+
}
23+
int main()
24+
{
25+
int testCase=1;
26+
cin>>testCase;
27+
while(testCase--){
28+
solve();
29+
}
30+
return 0;
31+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
int n;
12+
cin>>n;
13+
int ans=0;
14+
vector<int> a(n);
15+
for(auto &x:a){
16+
cin>>x;
17+
}
18+
a.resize(unique(a.begin(), a.end()) - a.begin());
19+
n = (int)a.size();
20+
for (int i = 0; i < n; i++)
21+
{
22+
if (i == 0 || i == n - 1 || (a[i]>a[i-1] && a[i]>a[i+1]) || (a[i]<a[i-1] && a[i]<a[i+1]))
23+
{
24+
ans += 1;
25+
}
26+
}
27+
cout << ans << '\n';
28+
return 0;
29+
}
30+
int main()
31+
{
32+
int testCase=1;
33+
cin>>testCase;
34+
while(testCase--){
35+
solve();
36+
}
37+
return 0;
38+
}

LeetCode/5665.Restore_the_Array_From_Adjacent_Pairs.cpp renamed to LeetCode/1743.Restore_the_Array_From_Adjacent_Pairs.cpp

File renamed without changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
string makeSmallestPalindrome(string s)
15+
{
16+
int n=s.size();
17+
for(int i=0;i<n/2;i++){
18+
char ch=min(s[i],s[n-1-i]);
19+
s[i]=ch;
20+
s[n-1-i]=ch;
21+
}
22+
return s;
23+
}
24+
};

LeetCode/885.Spiral Matrix III.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Solution
2020
vector<vector<int>> ans{{r, c}};
2121
int size = rows * cols, len = 1;
2222
int x = r, y = c;
23+
2324
while (ans.size() < size)
2425
{
2526
for (int j = 1; j <= len; j++)

0 commit comments

Comments
 (0)