15th March Shift 1 PDF
15th March Shift 1 PDF
Example:
Input:
3
123
444
337
Output:
-1
0
2
C++ #include <iostream>
#include <algorithm>
using namespace std;
int steps = 0;
while (true) {
arr[0] += 1;
arr[1] += 1;
arr[2] -= 1;
steps++;
sort(arr, arr + 3);
int main() {
int T;
cin >> T; // Number of test cases
while (T--) {
int P, Q, R;
cin >> P >> Q >> R;
cout << min_steps_to_equal(P, Q, R) << endl;
}
return 0;
}
PYTHON def min_steps_to_equal(P, Q, R):
arr = [P, Q, R]
arr.sort()
steps = 0
while True:
arr[0] += 1
arr[1] += 1
arr[2] -= 1
steps += 1
arr.sort()
# Input handling
T = int(input()) # Number of test cases
for _ in range(T):
P, Q, R = map(int, input().split())
print(min_steps_to_equal(P, Q, R))
JAVA import java.util.Arrays;
import java.util.Scanner;
int steps = 0;
while (true) {
arr[0] += 1;
arr[1] += 1;
arr[2] -= 1;
steps++;
Arrays.sort(arr);
Example Input:
3
03
26
10 1001
Example Output:
6 20 invalid input i&j i <=j<10000
Explanation:
1. Sum from 0 to 3: 0+1+2+3=6
2. Sum from 2 to 6: 2+3+4+5+6=20
3. Sum from 10 to 20: 10+11+⋯+20=165
MASSIVE SUCCESS RATE
"Transform Your Interview Opportunity into an Offer Letter and Make Your Parents
Proud!"
In-depth Technical Mock
Crack coding challenges with real experts.
HR & Managerial Prep
Master behavioral questions and impress TCS
Interviewer.
Full Interview Simulation
Ace both technical and HR in one session.
Resume Review
Identify and fix weaknesses for a standout CV.
Personalized Feedback & Expert Guidance
Tailored improvement tips to boost success.
www.primecoding.in
WWW.PRIMECODING.IN
JAVA import java.util.ArrayList;
import java.util.Scanner;
import java.util.Scanner;
int main() {
int T;
cin >> T;
cin.ignore();
int i, j;
if (!(ss >> i >> j)) {
cout << "Invalid input i&j i <= j < 10000" << endl;
continue;
}
return 0;
}
PYTHON
def range_sum(i, j):
return (j * (j + 1) // 2) - (i * (i - 1) // 2)
T = int(input())
for _ in range(T):
user_input = input()
values = user_input.split()
if len(values) < 2:
print("Invalid input i&j i <= j < 10000")
continue
i, j = map(int, values)