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 pb push_back
#define ll long long int
#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(){
int n;
cin>>n;
int a[n];
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
map<int,int> occ;
for (int i = 0; i < n-2; ++i)
{
if(gcd(a[i],a[i+2])>gcd(a[i],a[i+1])){
cout<<"NO"<<endl;
return;
}
}
cout<<"YES"<<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;
#define int long long
void solve(){
int n;
cin>>n;
vector<int> a(n),b(n);
int cnt1=0,cnt2=0;
int ok=0;
for(int i=0;i<n;i++){
cin>>a[i];
cnt1+=a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
cnt2+=(b[i]);
ok+=(a[i]!=b[i]);
}
cout<<min(ok,abs(cnt1-cnt2)+1)<<'\n';
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t=1;
cin>>t;
while(t--)
solve();
return 0;
}
‼️‼️‼️‼️‼️‼️‼️‼️‼️‼️‼️
Today's codeforces soln will be available for 🆓🆓🆓🆓🆓
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
class Solution {
public:
string robotWithString(string s) {
int cnt[26] = {0};
for(char ch:s) cnt[ch-'a']++;
string t = "",ans = "";
for(char ch:s) {
int small = -1;
for(int j = 0; j <= ch-'a' ;j++) {
if(cnt[j] > 0) {
small = j;
break;
}
}
cnt[ch-'a']--;
if (small < ch-'a') {
while(t.size() && t.back()-'a' <= small) ans+=t.back(),t.pop_back();
t+=ch;
}else{
while(t.size() && t.back()-'a' <= small) ans+=t.back(),t.pop_back();
ans+=ch;
}
}
reverse(t.begin(),t.end());
return ans+t;
}
};
class Solution {
public:
int mod = 1000000007;
int f(int i,int j,vector<vector<int>>& grid, int k,int pathSum,vector<vector<vector<int>>>&dp) {
if(i<0i>=grid.size()j<0||j>=grid[0].size())return 0;
if(dp[i][j][pathSum%k]!=-1)return dp[i][j][pathSum%k];
if(i==grid.size()-1 and j==grid[0].size()-1){
pathSum+=grid[i][j];
if(pathSum % k ==0){
return 1;
}
return 0;
}
int down = f(i+1,j,grid,k,pathSum+grid[i][j],dp) % mod;
int right = f(i,j+1,grid,k,pathSum+grid[i][j],dp) % mod;
return dp[i][j][pathSum%k]=((down+right)%mod);
}
int numberOfPaths(vector<vector<int>>& grid, int k) {
vector<vector<vector<int>>> dp(grid.size(), vector<vector<int>>(grid[0].size(), vector<int>(k, -1)));
int ans = f(0,0,grid,k,0,dp);
return ans%mod;
}
};
class Solution {
public:
vector findArray(vector& pref) {
int n = pref.size();
vectorans(n);
res[0] = pref[0];
for(int i = 1;i < n;i++){
res[i] = pref[i] ^ pref[i-1];
}
return res;
}
};
