Codeforces|Leetcode|Codechef free solutions
Open in Telegram
Free codeforces, Codechef, Leetcode solutions are available 😍😍😍😍😍😍 Helped More than 200+ students to crack coding round in 2022 and helped placed them in Good companies. 🥳🥳🥳🤩🤩🤩 Dm @Cpsoln if you want help in coding round.
Show more4 317
Subscribers
No data24 hours
-137 days
-5230 days
Posts Archive
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
pair<int,int> fun(int l, int r, vector<int>& ar,int &ans){
if(l==r){
return {ar[l],ar[r]};
}
int mid = (r+l)/2;
pair<int,int> a = fun(l,mid,ar,ans);
pair<int,int> b = fun(mid+1,r,ar,ans);
if(a.second>b.first){
ans++;
swap(a,b);
}
if(a.second==b.first-1 && b.second-a.first==(r-l)){
return {a.first,b.second};
}else{
ans = INT_MIN;
return {a.first,b.second};
}
}
void solve(){
int n;
cin>>n;
vector<int> a(n);
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
int ans =0;
fun(0,n-1,a,ans);
if(ans<0){
cout<<-1<<endl;
}else{
cout<<ans<<endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
clock_t t1=clock();
int t=1;
cin>>t;
while(t--){
solve();
}
}
#include<bits/stdc++.h>
using namespace std;
int a[200001],n,dp[200011];
vector<int> Q[200011];
void solve() {
cin >> n;
for(int i=1;i<=n;++i) cin >> a[i];
for(int i=0;i<=n+10;++i) {Q[i].clear();dp[i]=false;}
for(int i=1;i<=n;++i) {
int l=i,r=a[i]+i;
if(r<=n) Q[l].push_back(r);
l=i-a[i],r=i;
if(l>=1) Q[l].push_back(r);
}
dp[1]=true;
for(int i=1;i<=n;++i) {
if(!dp[i]) continue;
for(int j:Q[i]) dp[j+1]=true;
}
cout << (dp[n+1]?"YES":"NO") << endl;
}
int main() {
int T;
cin >> T;
while(T--) solve();
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define vi vector<ll>
vi divisors(ll n){vi div;for(ll i=1;i*i<=n;i++){ if(n%i==0) { div.pb(i); if(n/i!=i) div.pb(n/i); }} return div;}
void solve(){
ll n;
cin>>n;
ll a[n];
ll sum = 0;
for (int i = 0; i < n; ++i)
{
cin>>a[i];
sum+=a[i];
}
vi div = divisors(sum);
ll ans= n;
if(div.size()<=2){
cout<<n<<endl;
return;
}
for(auto x : div){
ll req = sum/x;
bool b = false;
ll s = 0;
ll thick = 0;
ll mx = 0;
for (int i = 0; i < n; ++i)
{
s+=a[i];
thick++;
if(s==req){
mx = max(thick,mx);
s= 0;
thick=0;
}else if(s>req){
b=true;
break;
}
}
if(!b){
ans = min(ans,mx);
}
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
clock_t t1=clock();
int t=1;
cin>>t;
while(t--){
solve();
}
}
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
string a,b;
cin>>a>>b;
int c1=0,c2=0;
for(int i=0,j=0;i<a.length(),j<b.length();i++,j++){
if(a[i]=='X')
c1++;
if(b[j]=='X')
c2++;
}
if(a[a.length()-1]=='S' && b[b.length()-1]=='M')
cout<<"<\n";
else if(a[a.length()-1]=='S' && b[b.length()-1]=='L')
cout<<"<\n";
else if(a[a.length()-1]=='M' && b[b.length()-1]=='L')
cout<<"<\n";
else if(a[a.length()-1]=='L' && b[b.length()-1]=='S')
cout<<">\n";
else if(a[a.length()-1]=='L' && b[b.length()-1]=='M')
cout<<">\n";
else if(a[a.length()-1]=='M' && b[b.length()-1]=='S')
cout<<">\n";
else{
if(a[a.length()-1]=='S'){
if(c1==c2)
cout<<"=\n";
else if(c1>c2)
cout<<"<\n";
else
cout<<">\n";
}
else{
if(c1==c2)
cout<<"=\n";
else if(c1>c2)
cout<<">\n";
else
cout<<"<\n";
}
}
}
return 0;
}
Today free codes of codeforces contest will be available
Subscribe the channel🥳🥳🥳🥳🥳
Repost from Codeforces|Leetcode|Codechef free solutions
Contact me before your coding round and book your slot
100% solutions guaranteed 🔥🔥🔥🔥🔥
‼️‼️‼️‼️‼️‼️‼️‼️‼️‼️
Solution for all companies will be available
🎁🎁🎁🎁🎁🎁🎁🎁🎁🎁🎁
Get a special discount
Dm @Cpsoln
‼️‼️‼️‼️‼️‼️‼️‼️‼️‼️‼️‼️
Don't trust on other telegram channels they will take money and block you
All channels are paid but this channel is giving code for free in very fast time
Subscribe more🔥🔥🔥🔥🔥🔥
ll n;
cin>>n;
ll arr[n];
for(int i=0;i>arr[i];
}
ll i =0;
ll j = 0;
ll k=1;
ll ans = 0;
while(jarr[j]){
i++;
k--;
}
ans+=(j-i+1);
j++;
k++;
}
cout<
