Welcome to the Editorial of IPC junior-2 (2025–26).
A. Seventy Percent Rule
Author: Femm_12
Math, Implementation
In this problem, it is given that Femina has attended x number of lectures and the professor has taken y number of lectures. For Femina to sit in the exam, she has to make her attendance atleast 70%. The percentage can be found out by (x/y)*100.We want this ratio to be greater than or equal to 70. So, we rearrange the equation to get x*100 >= 70*y So the answer is YES only if the ratio (in double) is greater than or equal to 70.00. Otherwise the answer is NO
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
// Check if attendance percentage is at least 70%
if (x * 100 >= 70 * y) {
cout << "YES\n";
} else {
cout << "NO\n";
}
return 0;
}
B. Aditya and Raj's Digit Sum challenge (Easy Version)
Author: Aditya_Dave, Raj_Patel_7807.
Math, Implementation
The solution is actually pretty simple. It is given that both A and B should be greater than or equal to 0. So, what if we fix one number from a and b to be 0? Then, we can definitely say that the other number will be N, and will satisfy both the given conditions. So, just output 0 and N for each test case.
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
long long int n;
cin >> n;
cout << 0 << " " << n << endl;
}
return 0;
}
C. The Palindrome Challenge (Easy Version)
Author: Raj_Patel_7807
String, Implementation, Brute Force
In this question, after working out on a few test case while doing the operations, it is easy to see that we could in fact, place every character at its right place after a few number of operations. According to the definition of palindrome strings, we know that if the length of the string is odd, there is only one character with an odd frequency, all the other characters should be of even frequency only. So, for odd length, check whether there is only one character with odd frequency, and for even length, all the character's frequency should be even.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
vector <int> freq(26, 0);
for (char c : s) {
freq[c — 'a']++;
}
int oddCount = 0;
for (int i = 0; i < 26; i++) {
if (freq[i] % 2 != 0)
oddCount++;
}
// A palindrome can have at most one character with odd frequency
if (oddCount <= 1)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
D. The Long-Arm Handshake
Author: zeel.18
Array, Implementation, Hashing
In here, the formal statement of the problem gives some good amount of idea to solve this question. We rearrange the equation to get i+a[i]=j-a[j]. Where, 1<=i<j<=n. So, we need to maintain the store of i+a[i] for every index i while traversing from left to right. At every index, we find the need of j-a[j]. We search, how many times does this occur in our hash map. And we add the frequency to our answer, because these are the number of pairs possible for the given index and also, we shall update our map accordingly
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n;
cin >> n;
map <long long,long long> mpp;
long long int ans=0;
for(int i = 0; i < n ; i++){
long long int x;
cin >> x;
long long int need=i-x;
if(mpp.count(need)>0) ans+=mpp[need];
mpp[i+x]++;
}
cout << ans << endl;
}
return 0;
}
E. Aditya and Raj's Digit Sum challenge (Hard Version)
Author: Aditya_Dave, Raj_Patel_7807
Math, Implementation
We are given a number as a string and need to split it into two positive numbers whose sum equals the original number, where the first number consists only of digits 0 and 1. To achieve this, we handle some edge cases separately and then construct the first number greedily from right to left. While traversing the string, we keep appending 0 to the first number for every 0 encountered, and when we find the first non-zero digit, we append 1 and decrease that digit by one, ensuring the subtraction remains valid. After reversing the constructed string, we obtain the required split. If no valid split is possible in special cases, we print -1. This approach works because borrowing from the rightmost possible position guarantees correctness while keeping the first number in the required form.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int n = s.size();
// If the string is "0"
if (s == "0") {
cout << -1 << "\n";
continue;
}
// If single digit and not "1"
if (n == 1 && s != "1") {
int x = s[0] - '0';
cout << 1 << " " << x - 1 << "\n";
continue;
}
// If only one '1' and rest are '0's, or s == "1"
int zeroCount = count(s.begin(), s.end(), '0');
if ((zeroCount >= n — 1 && s[0] == '1') || s == "1") {
cout << -1 << "\n";
continue;
}
string b = "";
// Traverse from right to left
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '0') {
b += '0';
} else {
b += '1';
s[i]--; // decrease digit by 1
break;
}
}
if (b.empty())
b = "1";
reverse(b.begin(), b.end());
cout << b << " " << s << "\n";
}
return 0;
}
F. The Palindrome Challenge (Hard Version)
Author: Raj_Patel_7807
Strings, Implementation
First, we check whether it is possible to rearrange the string into a palindrome by counting character frequencies, since a palindrome can have at most one character with an odd frequency; if this condition is violated, the answer is -1. Otherwise, we construct the palindrome using a two-pointer approach, where one pointer starts from the left and the other from the right. If the characters at both ends match, we move inward; if they do not, we search for a matching character on one side and reverse the corresponding substring to bring it to the correct position, recording this operation. Repeating this process ensures that each step fixes one mismatched pair, and eventually the string becomes a palindrome while keeping track of all performed reversals.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
string s;
cin >> n >> s;
// Count frequency of characters
vector<int> freq(26, 0);
for (char c : s) {
freq[c — 'a']++;
}
// Count odd frequency characters
int oddCount = 0;
for (int x : freq) {
if (x % 2 != 0)
oddCount++;
}
// If more than one odd count, palindrome impossible
if (oddCount > 1) {
cout << -1 << "\n";
continue;
}
vector<pair<int, int>> operations;
int i = 0, j = n - 1;
// Two-pointer approach
while (i < j) {
if (s[i] == s[j]) {
i++;
j--;
continue;
}
int k = i + 1;
while (k < j && s[k] != s[i])
k++;
if (k < j) {
// Found matching character on left side
reverse(s.begin() + k, s.begin() + j + 1);
operations.push_back({k + 1, j + 1});
} else {
// Match from right side
int kk = j - 1;
while (kk > i && s[kk] != s[j])
kk--;
reverse(s.begin() + i, s.begin() + kk + 1);
operations.push_back({i + 1, kk + 1});
}
i++;
j--;
}
// Output result
cout << operations.size() << "\n";
for (auto &op : operations) {
cout << op.first << " " << op.second << "\n";
}
}
return 0;
}
Explanations of all solutions contributed by Aditya_Dave.








Auto comment: topic has been updated by Aditya_Dave (previous revision, new revision, compare).
Auto comment: topic has been updated by Aditya_Dave (previous revision, new revision, compare).
Auto comment: topic has been updated by Aditya_Dave (previous revision, new revision, compare).