#include <bits/stdc++.h>
using namespace std;
int main()
{
int numTests;
cin >> numTests;
while(numTests--)
{
int length;
cin >> length;
string inputString;
cin >> inputString;
if (length % 3 == 1)
{
cout << "Yes\n";
continue;
}
bool flag = false;
for (char ch = 'a'; ch <= 'z'; ch++)
{
int firstIndex = length + 1, lastIndex = -1;
for (int i = 0; i < length; i++)
{
if (i % 3 == 0 && inputString[i] == ch)
{
firstIndex = i;
break;
}
}
for (int i = length - 1; i >= 0; i--)
{
int x = length - 1 - i;
if (x % 3 == 0 && inputString[i] == ch)
{
lastIndex = i;
break;
}
}
if (firstIndex < lastIndex)
{
flag = true;
break;
}
}
if (flag)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
Codechef 3-blast Palindrome
subscribe to the channel.
using namespace std;
int main()
{
int numTests;
cin >> numTests;
while(numTests--)
{
int length;
cin >> length;
string inputString;
cin >> inputString;
if (length % 3 == 1)
{
cout << "Yes\n";
continue;
}
bool flag = false;
for (char ch = 'a'; ch <= 'z'; ch++)
{
int firstIndex = length + 1, lastIndex = -1;
for (int i = 0; i < length; i++)
{
if (i % 3 == 0 && inputString[i] == ch)
{
firstIndex = i;
break;
}
}
for (int i = length - 1; i >= 0; i--)
{
int x = length - 1 - i;
if (x % 3 == 0 && inputString[i] == ch)
{
lastIndex = i;
break;
}
}
if (firstIndex < lastIndex)
{
flag = true;
break;
}
}
if (flag)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
Codechef 3-blast Palindrome
subscribe to the channel.
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, k, x, y;
cin >> n >> m >> k >> x >> y;
bool can_escape = true;
for (int i = 0; i < k; i++) {
int xi, yi;
cin >> xi >> yi;
int dx = abs(x - xi);
int dy = abs(y - yi);
if ((dx + dy) % 2 == 0) { // if Vika and friend are in same type of room
can_escape = false;
}
}
if (can_escape) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
Codeforces A
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, k, x, y;
cin >> n >> m >> k >> x >> y;
bool can_escape = true;
for (int i = 0; i < k; i++) {
int xi, yi;
cin >> xi >> yi;
int dx = abs(x - xi);
int dy = abs(y - yi);
if ((dx + dy) % 2 == 0) { // if Vika and friend are in same type of room
can_escape = false;
}
}
if (can_escape) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
Codeforces A
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
double a, b, c;
cin >> a >> b >> c;
double n = c / 30;
cout << ceil((n + a) / b) << '\n';
}
}
Codechef Endless Appetizers
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
double a, b, c;
cin >> a >> b >> c;
double n = c / 30;
cout << ceil((n + a) / b) << '\n';
}
}
Codechef Endless Appetizers
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vi a(n);
unordered_map<int, int> mp;
int temp = 0, ans = 0;
rep(i,0,n){
cin >> a[i];
mp[a[i]]++;
if(mp[a[i]]&1){
temp++;
}
else temp--;
ans = max(ans, temp);
}
cout << ans;
}
}
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vi a(n);
unordered_map<int, int> mp;
int temp = 0, ans = 0;
rep(i,0,n){
cin >> a[i];
mp[a[i]]++;
if(mp[a[i]]&1){
temp++;
}
else temp--;
ans = max(ans, temp);
}
cout << ans;
}
}
Coding Corner | Codeforces | Codechef | Leetcode | Solutions for Free
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while(t--){ int n; cin >> n; vi a(n); unordered_map<int, int> mp; int temp = 0, ans = 0; rep(i,0,n){ cin >> a[i]; …
Codechef Card Swipe DONE
Guys please share my youtube channel I would be very happy :)
https://www.youtube.com/@codehelperr_nnw
Guys please share my youtube channel I would be very happy :)
https://www.youtube.com/@codehelperr_nnw
long long n;
cin >> n;
vector<long long> a(n);
long long sum = 0;
for(int i=0; i<n; i++){
cin >> a[i];
sum+=a[i];
}
sort(a.begin(), a.end());
long long i = 0;
do {
cout << sum << ' ';
sum-=a[i];
i++;
}while(sum);
Codechef next problem DONE
SHare the chennel please!
cin >> n;
vector<long long> a(n);
long long sum = 0;
for(int i=0; i<n; i++){
cin >> a[i];
sum+=a[i];
}
sort(a.begin(), a.end());
long long i = 0;
do {
cout << sum << ' ';
sum-=a[i];
i++;
}while(sum);
Codechef next problem DONE
SHare the chennel please!
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int change_mod(int curr, int req) {
int m1 = curr % 3;
int m2 = req % 3;
if (m1 == m2)
return 0;
if (m1 < m2)
return m2 - m1;
return m2 + (3 - m1);
}
int solver(vector<int>& a) {
int ans = 0;
for (int i = 3; i < a.size(); i++) {
ans += change_mod(a[i], a[i - 3]);
a[i] = a[i - 3];
}
return ans;
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int>> X;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (((i + j + k) % 3) == 0)
X.push_back({ i, j, k });
}
}
}
int ans = 1e9;
for (auto vec : X) {
vector<int> temp = vec;
for (auto x : a) temp.push_back(x);
ans = min(ans, solver(temp));
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int totalTests = 1;
cin >> totalTests;
for (int testNo = 1; testNo <= totalTests; testNo++) {
solve();
}
return 0;
}
Codechef Segment Three done
#include <vector>
#include <algorithm>
using namespace std;
int change_mod(int curr, int req) {
int m1 = curr % 3;
int m2 = req % 3;
if (m1 == m2)
return 0;
if (m1 < m2)
return m2 - m1;
return m2 + (3 - m1);
}
int solver(vector<int>& a) {
int ans = 0;
for (int i = 3; i < a.size(); i++) {
ans += change_mod(a[i], a[i - 3]);
a[i] = a[i - 3];
}
return ans;
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int>> X;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (((i + j + k) % 3) == 0)
X.push_back({ i, j, k });
}
}
}
int ans = 1e9;
for (auto vec : X) {
vector<int> temp = vec;
for (auto x : a) temp.push_back(x);
ans = min(ans, solver(temp));
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int totalTests = 1;
cin >> totalTests;
for (int testNo = 1; testNo <= totalTests; testNo++) {
solve();
}
return 0;
}
Codechef Segment Three done
Guys please share my youtube channel.
All Contest codes will be available in this youtube channel.
https://www.youtube.com/@codehelperr_nnw
All Contest codes will be available in this youtube channel.
https://www.youtube.com/@codehelperr_nnw
👍2
Guys I am getting plagiarized, that's why I am not sharing codes
If you promise me to not just copy I will share the codes again
If you promise me to not just copy I will share the codes again
👍7