Class Questions Problem Solving
Class Questions Problem Solving
return count;
}
Greedy
Minimum [Link]
Platforms 1587115620/1
Problem
code
Merge [Link]
intervals
Code vector<vector<int>> merge(vector<vector<int>>
&intervals) {
if([Link]() == 0) return {};
sort([Link](), [Link]());
vector<vector<int>> result;
int start = intervals[0][0];
int end = intervals[0][1];
for(int i = 1; i < [Link](); i++){
if(intervals[i][0] <= end){
end = max(end, intervals[i][1]);
} else {
result.push_back({start, end});
start = intervals[i][0];
end = intervals[i][1];
}
}
result.push_back({start, end});
return result;
}
Non- [Link]
overlapping
Intervals
int eraseOverlapIntervals(vector<vector<int>>
&intervals) {
int n = [Link]();
sort([Link](), [Link](),
[](vector<int> &a, vector<int> &b) {
return a[1] < b[1];
});
int count = 1;
int lastFinish = intervals[0][1];
for (int i = 1; i < n; i++) {
if (intervals[i][0] >= lastFinish)
count++;
else
continue;
lastFinish = intervals[i][1];
}
return n - count;
}
Insert Interval [Link]
Maximum [Link]
Meetings in in-one-room/1?
One Room itm_source=geeksforgeeks&itm_medium=article&itm_campaign
=practice_card
#include <bits/stdc++.h>
using namespace std;
vector<int> partitionLabels(string s) {
int start = 0, end = 0;
unordered_map<char, int> mp;
for (int i = 0; i < [Link](); i++)
mp[s[i]] = i;
vector<int> result;
for (int i = 0; i < [Link](); i++) {
end = max(mp[s[i]], end);
if (end == i) {
result.push_back(end - start + 1);
start = end + 1;
}
}
return result;
}
Fractional [Link]
Knapsack knapsack-1587115620/1
sort([Link](), [Link]());
int totalStocks = 0;
totalStocks += canBuy;
k -= canBuy * cost;
if (k == 0) break;
}
return totalStocks;
}
Job [Link]
Sequencing 1587115620/1
Problem
struct Job {
int id, dead, profit;
};
int maxDeadline = 0;
for (int i = 0; i < n; i++)
maxDeadline = max(maxDeadline, arr[i].dead);
Recursion
Ispalindrome
bool fun(string &s, int left, int right){
if(s[left] != s[right]) return false;
if(left >= right) return true;
return fun(s, left+1, right-1);
}
bool isPalindrome(string S) {
return fun(S, 0, [Link]()-1);
}
Subsets - 1
vector<vector<int>> result;
void fun(vector<int> &nums, int i, vector<int> temp){
if(i == [Link]()){
result.push_back(temp);
return;
}
fun(nums, i+1, temp);
temp.push_back(nums[i]);
fun(nums, i+1, temp);
temp.pop_back();
}
vector<vector<int>> subsetsWithDup(vector<int>& nums)
{
vector<int> temp;
fun(nums, 0, temp);
sort([Link](), [Link]());
return result;
}
Subsets - II
vector<vector<int>> result;
void fun(int i, vector<int> &arr, vector<int> &ans) {
if (i == [Link]()) {
result.push_back(ans);
return;
}
ans.push_back(arr[i]);
fun(i + 1, arr, ans);
ans.pop_back();
int j = i + 1;
while (j < [Link]() && arr[i] == arr[j])
j++;
fun(j, arr, ans);
}
Binary Strings
vector<string> result;
if (temp[[Link]() - 1] == '1') {
fun(i + 1, n, temp + '0');
temp.pop_back();
}
}
vector<string> validStrings(int N) {
fun(1, N, "0");
fun(1, N, "1");
return result;
}
Combinations
Prefix Sum HWI
Longest
subarray with
sum divisible
by k
Code int func(int N, int K, vector<int>& nums) {
unordered_map<int, int> mp;
int len = 0;
int presum = 0;
if(temp == 0)
len = max(len, i + 1);
else {
if([Link](temp) != [Link]())
len = max(len, i - mp[temp]);
}
mp[temp] = i;
}
if(len == 0)
return -1;
else
return len;
}
Longest
subarray with
equal 0 and 1
Code int func(int N, vector<int>& nums) {
int len = 0;
vector<int> temp(N);
for(int i = 0; i < N; i++) {
if(nums[i] == 0)
temp[i] = -1;
else
temp[i] = 1;
}
unordered_map<int, int> mp;
int presum = 0;
for(int i = 0; i < N; i++) {
presum += temp[i];
if(presum == 0)
len = max(len, i + 1);
else {
if([Link](presum) != [Link]()) {
len = max(len, i - mp[presum]);
} else {
mp[presum] = i;
}
}
}
if(len == 0)
return -1;
else
return len;
}
Count
subarrays with
equal 0 and 1
int func(int N, vector<int>& nums) {
int count = 0;
vector<int> temp(N);
for(int i = 0; i < N; i++) {
if(nums[i] == 0)
temp[i] = -1;
else
temp[i] = 1;
}
unordered_map<int, int> mp;
int presum = 0;
for(int i = 0; i < N; i++) {
presum += temp[i];
if(presum == 0) {
count++;
}
if([Link](presum) != [Link]()) {
count += mp[presum];
}
mp[presum]++;
}
return count;
}
#include <bits/stdc++.h>
using namespace std;
int func(int N, vector<int>& L, vector<int>& R) {
int maxVal = *max_element([Link](), [Link]());
int newsize = maxVal + 2;
vector<int> freq(newsize, 0);
for(int i = 0; i < N; i++) {
freq[L[i]]++;
freq[R[i] + 1]--;
}
int prefix = freq[0];
for(int i = 1; i < newsize; i++) {
prefix += freq[i];
freq[i] = prefix;
}
return max_element([Link](), [Link]()) -
[Link]();
}
Priority Queue + Greedy
Minimum
Cost of
Ropes
Code - priority_queue<int, vector<int>, greater<int>> pq;
for (int x : ropes) [Link](x);
int cost = 0;
while ([Link]() > 1) {
int first = [Link]();
[Link]();
int second = [Link]();
[Link]();
int sum = first + second;
cost += sum;
[Link](sum);
}
return cost;
}
Maximum
number of
events that
can be
attended
Code
Tab 1
Test Questions
Title Given two non-empty strings, S1 and S2, containing digits, alphabets, and
special characters. Generate a digit code (C) by extracting the digits from S1
and S2, such that C has a digit from the first string followed by a digit from the
second string. If you run out of digits in S1 or S2, append the remaining digits
from the other string at the end of C. See sample test case for better
understanding.
Input Two lines containing S1 and S2.
Format
Output A single string in a single line.
Format
Constraint 1 <= len(S1), len(S2) <= 100
Sample a4b1$c3d4x89
Input 1 b2c9*t7
Sample 421937489
Output 1
Explanatio S1 = "a4b1$c3d4x89", and S2 = "b2c9*t7". First digits from S1 and S2 are "4"
n1 and "2" respectively. C is 42. Second digits from S1 and S2 are "1" and "9"
respectively. C becomes 4219. Third digits from S1 and S2 are "3" and "7"
respectively. C becomes 421937. S2 has run out of digits. Append all the
remaining digits from S1 to C to get 42193789. Hence the answer.
Test Case a4b1$c3d4x89
Input 1 b2c9*t7
Test Case 421937489
Output 1
Test Case &61)9B26gdjsonc))0
Input 2 bc
Test Case 619260
Output 2
Test Case 0bm8
Input 3 ncjdns0esncbcdy1bhdheu2847%^&*(3
Test Case 008128473
Output 3
Test Case 0g0n0d0g0g
Input 4 1*1(1H1&
Test Case 010101010
Output 4
Test Case a5b1$c3d4x8-23
Input 5 b2c9*t7
Test Case 5219374823
Output 5
Test Case b1n2m3
Input 6 b5j6k7
Test Case 152637
Output 6
Test Case u7ty45hfjhfha2jfdh3jdfh
Input 7 x3jhf6jfdjhf4djfhjf36&
Test Case 7346542336
Output 7
Test Case gjkj49jkj393jkjh
Input 8 djd7nf9f
Test Case 4799393
Output 8
Test Case fj12
Input 9 jf45kjfkj8fj
Test Case 14258
Output 9
Test Case fj12f
Input 10 jf45kjfkj8fj
Test Case
Output 10
Test Case gjkfdj39fj9df
Input 11 5
Test Case 3599
Output 11
2 3 6 5 7 35 11 13 143 17 19 323 …
The series begins with the first two prime numbers (2 and 3) followed by their
product (6). The next pair of consecutive prime numbers (5 and 7) is then
printed followed by their product (35) and so on.
Title
Single Digit Sum
Given a number N and a natural number K > 0. Concatenate N, K times. Then
repeatedly add all the digits of the resultant number, until the result has only a
single digit.
Input First line of Input contains the number N and the second line contains K (number of
Format times N has to be concatenated).
Output Return single digit sum.
Format
Constraint 1 <= N <= 10^4
1 <= K <= 10
Sample 9875
Input 1 4
Sample 8
Output 1
Explanatio N = 9875 and K = 4. After the concatenation, the resultant number is,
n 9875987598759875. Adding all the digits we get, 116 ( = 5 + 7 + 8 + 9 + 5 + 7 + 8 +
9 + 5 + 7 + 8 + 9 + 5 + 7 + 8 + 9). Adding all the digits of 116 we get, 8 (= 1 + 1 + 6).
Test Case 315
Input 1 4
Test Case 9
Output 2
Test Case 9
Input 2 2
Test Case 9
Output 2
Test Case 15
Input 3 1
Test Case 6
Output 3
Test Case 987
Input 4 8
Test Case 3
Output 4
Test Case 5
Input 5 1
Test Case 5
Output 5
Title
All Armstrongs
An Armstrong number is the one whose sum of the nth power of its digits is equal
to the number itself. Your task is to print all the Armstrong numbers in the range
[lower, upper]. If no Armstrong Number is found between the given range, print -1.
Input Two integer values each in a new line representing lower and upper.
Format
Output Space separated armstrong numbers in range or -1.
Format
Constraint 1 < numbers < 10 ^ 5
Sample 100
Input 1 999
Sample 153 370 371 407
Output 1
Test Case 1
Input 1 100
Test Case 123456789
Output 1
Test Case 500
Input 2 1000
Test Case -1
Output 2
Test Case 1000
Input 3 10000
Test Case 1634 8208 9474
Output 3
Test Case 100
Input 4 200
Test Case 153
Output 4
Test Case 200
Input 5 300
Test Case -1
Output 5
Jumping Numbers
Statement Given a positive number X. Find all jumping numbers smaller than or equal to X. A
number is called a jumping number if all adjacent digits in it differ by only 1. All
single digit numbers are considered as jumping numbers.
Input Single line of input containing the value of X.
Format
Output Output all the jumping numbers in sorted order.
Format
Constraint 1 <= X <= 10^4
Sample 50
Input 1
Sample 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45
Output 1
Explanatio 0 to 9 are all single digit numbers. They all are considered jumping numbers. The
n difference between any two subsequent digits of other numbers is 1. For example,
in 12, 1 and 2 differ by 1, and in 32, 3 and 2 differ by 1. Therefore they are
considered jumping numbers. Whereas, in 24, 2 and 4 differ by 2, hence they are
not considered jumping numbers.
Test Case 5
Input 1
Test Case 012345
Output 1
Test Case 15
Input 2
Test Case 0 1 2 3 4 5 6 7 8 9 10 12
Output 2
Test Case 200
Input 3
Test Case 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45 54 56 65 67 76 78 87 89 98 101 121
Output 3 123
Test Case 2000
Input 4
Test Case 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45 54 56 65 67 76 78 87 89 98 101 121
Output 4 123 210 212 232 234 321 323 343 345 432 434 454 456 543 545 565 567 654 656
676 678 765 767 787 789 876 878 898 987 989 1010 1012 1210 1212 1232 1234
Test Case 5000
Input 5
Test Case 0 1 2 3 4 5 6 7 8 9 10 12 21 23 32 34 43 45 54 56 65 67 76 78 87 89 98 101 121
Output 5 123 210 212 232 234 321 323 343 345 432 434 454 456 543 545 565 567 654 656
676 678 765 767 787 789 876 878 898 987 989 1010 1012 1210 1212 1232 1234
2101 2121 2123 2321 2323 2343 2345 3210 3212 3232 3234 3432 3434 3454
3456 4321 4323 4343 4345 4543 4545 4565 4567
Sum Merge
You are given two sorted arrays of size N each. Merge the given sorted arrays in
sorted order and print the sum of two middle elements after merging the arrays.
Input Three lines of input. The first line contains integer N. The next two lines contain
Format array elements in space separated format
Output Print the sum of the middle elements of the array after merging in sorted order.
Format
Constraint Both arrays are of equal size.
1 < N < 100
1 <= arr[i] <= 1000
Sample 5
Input 1 10 20 30 35 40
25 32 45 50 55
Sample 67
Output 1
Explanatio The sorted merged array is, 10, 20, 25, 30, 32, 35, 40, 45, 50, 55. The sum of the
n two middle elements (marked as bold) is 67
Test Case 5
Input 1 12345
6 7 8 9 10
Test Case 11
Output 1
Test Case 3
Input 2 10 20 30
15 25 35
Test Case 45
Output 2
Test Case 6
Input 3 1 2 3 10 11 12
456789
Test Case 13
Output 3
Test Case 5
Input 4 21 22 24 26 28
10 20 30 40 50
Test Case 50
Output 4
Test Case 2
Input 5 11
11
Test Case 2
Output 5
Test Case 5
Input 6 5 15 25 35 45
10 20 30 40 50
Test Case 55
Output 6
Class Position
Statement The marks of N students of a particular class are given as space separated values.
Find out the position of each student in the class. Position 1 is assigned to a student
with maximum marks and so on. If two students get the same marks then both will
be assigned the same position and the next position will be skipped. See sample
case for further explanation.
Input Two lines of input. The first line contains integer N. Next line contain array
Format elements in space separated format
Output Array of positions in space separated format.
Format
Constraints 1 <= N <= 60
0 <= arr[i] <= 100
Sample 5
Input 1 10 56 87 40 90
Sample 53241
Output 1
Explanatio The position of the first student (with 10 marks) is 5th. The position of the second
n student (with 56 marks) is 3rd. Similarly, the position of the last student (with 90
marks) is first. Therefore, the output is 5 3 2 4 1.
Sample 6
Input 2 80 56 97 80 90 90
Sample 461422
Output 2
Explanatio The position of the first student (with 80 marks) is 4th. The position of the second
n student (with 56 marks) is 6th. Positions of the last two students(90 marks each) is
2nd. Therefore, both of them are assigned 2nd position and the 3rd position is
skipped. The output is, 4 6 1 4 2 2.
Test Case 5
Input 1 100 65 80 40 90
Test Case 14352
Output 1
Test Case 6
Input 2 80 80 97 80 90 90
Test Case 441422
Output 2
Test Case 6
Input 3 100 100 100 90 95 80
Test Case 111546
Output 3
Test Case 4
Input 4 50 40 30 20
Test Case 1234
Output 4
Test Case 6
Input 5 555555
Test Case 111111
Output 5
Test Case 4
Input 6 80 70 80 60
Height Checker
Statement N students are standing in a line in random order. But they are expected to be
standing in non decreasing order. You are given an integer array whose ith value
represents the height of the student standing at the ith position. Return the count
of the students who are not standing in their expected positions.
Input Two lines of input. The first line contains integer N. Next line contain array
Format elements in space separated format
Output Single integer.
Format
Constraint 1 <= N <= 100
1 <= heights[i] <= 100
Sample 6
Input 1 114213
Sample 3
Output 1
Explanatio Students standing at the 2nd, 4th and 5th indexes are not standing at their
n expected positions. They should have been standing at the 5th, 2nd and 4th index
positions. Therefore the output is 3.
Test Case 5
Input 1 51234
Test Case 5
Output 1
Test Case 5
Input 2 12345
Test Case 0
Output 2
Test Case 5
Input 3 42315
Test Case 2
Output 3
Test Case 8
Input 4 213546789
Test Case 4
Output 4
Test Case 6
Input 5 546789
Test Case 2
Output 5
Test Case 5
Input 6 13425
Test Case 3
Output 6
Rearrange Array
Statement Given an array of integers. Your task is to print the array in the following order -
smallest number, largest number, 2nd smallest number, 2nd largest number, 3rd
smallest number, 3rd largest number and so on.
Input Two lines of input. The first line contains integer N. Next line contain array
Format elements in space separated format
Output Single line of space separated integers.
Format
Constraint 1 <= N <= 10^3
1 <= arr[i] <= 10^3
Sample 4
Input 1 1584
Sample 1845
Output 1
Explanatio Smallest is 1. Largest is 8. Second smallest is 4. And the second largest is 5.
n Therefore the output is 1 8 4 5.
Test Case 9
Input 1 581429376
Test Case 192837465
Output 1
Test Case 4
Input 2 4321
Test Case 1423
Output 2
Test Case 1
Input 3 20
Test Case 20
Output 3
Test Case 4
Input 4 1234
Test Case 1423
Output 4
Test Case 5
Input 5 13425
Test Case 15243
Output 5
Majority Element
Statement Given an array of size n. Print the majority element. The majority element is the
element that appears more than ⌊n/2⌋ times. You may assume that the array is
non-empty. If there is no majority element print "No Majority Element" without
quotes.
Input Two lines of input. The first line contains integer N. Next line contain array
Format elements in space separated format
Output Return majority element if any otherwise print No Majority Element.
Format
Constraint 1 <= N <= 10^3
-10^3 <= arr[i] <= 10^3
Sample 7
Input 1 2211122
Sample 2
Output 1
Explanatio 2 is appearing than 4 times, which is greater than 3 (= ⌊7/2⌋).
n
Sample 8
Input 2 33424424
Sample No Majority Element
Output 2
Explanatio No element is appearing more than 4 (= ⌊8/2⌋) times.
n
Test Case 9
Input 1 334244244
Test Case 4
Output 1
Test Case 20
Input 2 43788128382286888888
Test Case 8
Output 2
Test Case 7
Input 3 2 22 2 3 3 1 1
Test Case No Majority Element
Output 3
Test Case 5
Input 4 -1 -1 2 3 -1
Test Case -1
Output 4
Test Case 6
Input 5 113343
Test Case No Majority Element
Output 5
Nani House
Statement A kid, having N toys, is going to his Nani house for summer vacation. He wants to
carry some toys. But he can lift upto 5 kg (5000 grams) in weight. Find out the
maximum number of toys he can go with. You will be given an array of integers,
whose ith element represents the weight of the ith toy.
Input Two lines of input. The first line contains integer N. Next line contain array
Format elements in space separated format
Output Single integer.
Format
Constraint 1 <= N <= 50
1 <= weight[i] <= 9999
Sample 7
Input 1 200 1800 1200 1500 500 800 4000
Sample 5
Output 1
Explanatio The only possible largest combination of toys, which has the least total weight
n consists of 1st, 3rd, 4th, 5th and 6th toys. The weight of this combination is 4200.
Therefore the output is 5.
Test Case 8
Input 1 2000 3000 1500 1400 800 1200 600 2500
Test Case 4
Output 1
Test Case 11
Input 2 100 1010 1200 800 700 1500 600 2500 3000 8000 900
Test Case 6
Output 2
Test Case 10
Input 3 100 200 300 400 1200 18000 1800 2000 3000 10000
Test Case 6
Output 3
Test Case 6
Input 4 200 500 100 800 500 100
Test Case 6
Output 4
Test Case 7
Input 5 100 200 1700 1800 600 9000 8900
Test Case 5
Output 5
Password Matching
11 As part of developing a new password management system, your task is to validate
whether the new password is correct or not. You are given two words, S and R, and
T integers.
Positive integers represent right rotation by the given value and negative integers
represent left rotation by the given value.
Apply these T operations on S and compare the result with R. If they are the same
"Password Accepted" (without quotes) else print "Try Again" (without quotes).
Input Three lines of input. First line contains two space separated words (S and R). The
Format second line contains an integer (T). And the third line contains T space separated
integers values.
Output "Password Accepted" (without quotes) or "Try Again" (without quotes).
Format
Constraint 1 < S, R < 10^3
1 <= T <= 100
-50 <= arr[i] <= 50
Sample Hello Hello
Input 1 3
1 3 -2
Sample Try Again
Output 1
Explanatio S is Hello. Right rotation by 1 position gives oHell. Again right rotation by 3
n positions gives elloH. Left rotation by 2 times gives loHel. This is not equal to Hello.
Hence the output is Try Again.
Test Case eat&treat& &treat&eat
Input 1 3
7 4 -11
Test Case Try Again
Output 1
Test Case helloworld& world&hello
Input 2 7
-2 6 4 -8 2 1 3
Test Case Password Accepted
Output 2
Test Case doneisbetter isdonebetter
Input 3 4
-10 -5 25 -2
Test Case Try Again
Output 3
Test Case doneisbetter isdonebetter
Input 4 3
12 -24 36
Test Case Try Again
Output 4
Test Case Hello Hello
Input 5 1
55
Move Sections
12 You are given a string S of length greater than 5. You have to create a new resultant
string such that every fourth and sixth character present in the string is moved to
the end of the string in the order as they appear in the original string. Print the
newly created string.
Input Single line containing string S.
Format
Output Single line containing string.
Format
Constraint 5 <= len(S) <= 10^6
Sample quickfoxjumps
Input
Sample quikojumscfxp
Output
Explanatio c, f, x and p are fourth and sixth characters in S, which are moved to the end.
n
Test Case ohelloohelloohelloX
Input 1
Test Case oheloellohelXloholo
Output 2
Test Case SRmByYFmNBZsveKRqoGaHHQMHBSnNzJHEIUzjtASDscAdAaBnKpinvmVTPTqfD
Input 2 QimonOgytXoJkJQrYitMSOhZVDpwModBakxjkQO
Test Case SRmyFNBZveKqGHHQHBSNJEIUjtADcdAanKpnmTPTfDQmngytoJkQYtMShZVpMd
Output 2 BaxjkOBYmsRoaMnzHzSsABivVqioOXJriODwokQ
Test Case DoctorWho
Input 3
Test Case DocoWotrh
Output 3
Test Case October052020
Input 4
Test Case Octbr5200oe02
Output 4
14
Remove From Selected
Statement Given two strings S1 and S2, remove those characters from the first string which
are present in the second string. Both the strings contain only lowercase
characters. Print S1 after removal of characters.
Input Two strings S1 and S2 are given in two lines.
Format
Output A single string.
Format
Constraint 0 <= length(S1), length(S2) <= 10^3
Sample hello
Input 1 ihedfghj
Sample llo
Output 1
Explanatio Characters 'h' and 'e' from S1 are present in S2. Remaining string after removing
n these characters from S1 is 'llo'.
Test Case parul
Input 1 rahul
Test Case p
Output 2
Test Case abhishek
Input 2 abhigyan
Test Case sek
Output 2
Test Case priyanshu
Input 3 priyanshi
Test Case u
Output 3
Test Case rishu
Input 4 qltr
Test Case ishu
Output 4
15
Reverse Letters Only
Statement You are given a string S consisting of alphabets, digits and special characters.
Reverse only alphabets(uppercase or lowercase). Except alphabets all other
characters will remain in the same position.
Input Single line containing the input string, S.
Format
Output Single line of output containing a string.
Format
Constraints len(S) <= 10^6.
Sample abcd-e
Input 1
Sample edcb-a
Output 1
Explanatio - is the only special character. In the output string, only - has retained its original
n position and the remaining string has been reversed.
Test Case a-bC-dEf-ghIj
Input 1
Test Case j-Ih-gfE-dCba
Output 1
Test Case Test1ng-Leet=code-Q!
Input 2
Test Case Qedo1ct-eeLg=ntse-T!
Output 2
Test Case --!@#
Input 3
Test Case --!@#
Output 3
Test Case abcd--!#
Input 4
Test Case dcba--!#
Output 4
Test Case abcde
Input 5
Test Case edcba
Output 5
Palindrome and Reverse
16 Split the given string (S) in two parts from the midpoint. Reverse each part and join
them to form a new string (T). If T is palindrome, print True otherwise print False.
Note: If len(S) is odd, add the middle character to the right substring.
Input Single line of input containing S.
Format
Output "True" or "False" (without quotes).
Format
Constraint 2 <= len(S) <= 10^6
Sample Hello
Input 1
Sample False
Output 1
Explanatio Splitting "Hello" in two parts we get "He" and "llo". Reversing and adding them we
n get, "eHllo", which is not a palindrome, hence False is printed.
Test Case alula
Input 1
Test Case False
Output 2
Test Case A dog, a plan, a canal: pagoda
Input 2
Test Case False
Output 2
Test Case ABCCBAD
Input 3
Test Case True
Output 3
Test Case A dog god A
Input 4
Test Case False
Output 4
Test Case helleh
Input 5
Test Case True
Output 5
17
Not Vowel
Statement From a given list of N words, print those words which do not contain any vowel. If
all the words have vowels in them, print -1 instead.
Input Two lines of input. First line contains N and the second line contains N space
Format separated words.
Output Space separated words or -1
Format
Constraint 1 < N <= 10^3
Sample 3
Input 1 Kite Google BMW
Sample BMW
Output 1
Test Case 3
Input 1 Preet Jeet Crypt
Test Case Crypt
Output 2
Test Case 3
Input 2 Japan Russia China
Test Case -1
Output 2
Test Case 2
Input 3 Jjpr qytr
Test Case Jjpr qytr
Output 3
Test Case 3
Input 4 Bbllr Jpwqeggdds
Test Case Bbllr
Output 4
Abbreviation
18 A string abbreviation is considered valid if the abbreviated string has at least 3
characters and a maximum of 5 characters. In addition, the abbreviated string
should contain alphabets in the same order as they appear in the original string.
Your task is to write a function which checks if the abbreviation is correct and
returns a boolean response.
Input Single line of input containing two space separated strings.
Format
Output "True" or "False" (without quotes).
Format
Sample Boulevard Blvd
Input 1
Sample True
Output 1
Explanatio The abbreviation is Blvd. All of its characters are part of Boulevard, the original
n string. They appear in the same order in the original string and the length of
abbreviation is greater than 3 and less than 5. Hence it is a valid abbreviation.
Test Case department dmpt
Input 1
Test Case False
Output 1
Test Case minimum min
Input 2
Test Case True
Output 2
Test Case approximately aplty
Input 3
Test Case False
Output 3
Test Case Boulevard BBlvd
Input 4
Test Case False
Output 4
Compress Recurrences
Statement You are given a string and a compression value (an integer, n). Count the frequency
of consecutive occurrences of each character in the string. If the frequency is
greater than or equal to the compression value, print the character followed by its
frequency. Otherwise print the characters as they appear in the original string.
Input Two lines of input. The first line contains the value of the string and the second line
Format contains the value of n.
Output Print the new alphanumeric string.
Format
Constraint 5 <= len(s1) <= 10^3
Sample aaabbsdgfdhaaaaaa
Input 1 3
Sample a3bbsdgfdha6
Output 1
Explanatio 'a' appears 3 times (equal to the compression value) hence it is printed as a3. 'B'
n appears two times (less than the compression value) hence it is printed as 'bb'.
Similar logic is to be applied for other characters too. Hence the final output is
'a3bbsdgfdha6'.
Test Case aaaaabb
Input 1 3
Test Case a5bb
Output 1
Test Case etNGeetNGeetNGe
Input 2 1
Test Case e1t1N1G1e2t1N1G1e2t1N1G1e1
Output 2
Test Case ohelloohelloohello
Input 3 3
Test Case ohelloohelloohello
Output 3
Test Case ohelloohelloohello
Input 4 1
Test Case o1h1e1l2o2h1e1l2o2h1e1l2o1
Output 4
9
String Validation
Given a string S, determine if it contains both the characters '&' and '#' and the
length of the string is even. If both conditions are satisfied, print 'YES';
otherwise, print 'NO’.
Input Single line input string
Format
Output "YES" or “NO”.
Format
Sample abc&def#
Input 1
Sample YES
Output 1
Explanation String contains “&” and “#” and length of string is even 8
Sample hello&world
Input 2
Sample NO
Output 2
Explanation String contains not contain “#”
Test Case &#
Input 1
Test Case YES
Output 1
10
Adding first-2 and last element-2 of list
Given N integers. Find the sum of the first 2 elements and last 2 elements in
separate lines. You can assume that N >= 4.
Input First line contains N. The next line contains the N space separated integers.
Format
Output Two integer in two different line.
Format
Sample 18
Input 1 2 3 4 5 6 7 8 9 10 12 13 15 21 22 45 90 100
Sample 3
Output 190
Test Case 4
Input 1 1111
Test Case 2
Output 2 2
Test Case 5
Input 2 11222
Test Case 2
Output 2 4
Test Case 5
Input 3 -1 -4 0 0 0
Test Case -5
Output 3 0
Test Case 4
Input 4 10 20 -34 10
Test Case 30
Output 4 -24
11
Count and Compare Odds and Evens
Given a list of N positive integers. You need to find out the count of odd and even
integers. If the count of odd integers are greater than the count of even integers,
print "Odd" (without quotes). If the count of even integers are greater than the
count of odd integers, print "Even" (without quotes). Print "Tie" (without quotes)
if count of odd and even integers are equal.
Input Two lines of input. First line contains an integer N, represting the total number of
Format integers. Second line of input contains N space separated integers.
Output Single string in single line.
Format
Sample 5
Input 1 10 24 3 37 38
Sample Even
Output 1
Test Case 8
Input 1 12345678
Test Case Tie
Output 1
Test Case 7
Input 2 1 3 5 7 9 11 13
Test Case Odd
Output 2
Test Case 4
Input 3 10 2 8 16
Test Case Even
Output 3
12
Group Salary Summation
You are given salaries of N groups of employees (each group has M employees) in
the format specified below. The count of employees in each group may not be the
same. Print the sum of salaries of each group of employees.
Input First line contains the value of N, followed by N pairs of lines. The first line of each
Format pair contains the value of M and the second line of each pair contains space
separated M integers, denoting the salary of each employees.
Output N lines, each having single integer.
Format
Sample 3
Input 1` 4
12000 10000 5000 8000
2
3000 2000
3
7000 9000 5000
Sample 35000
Output 1 5000
21000
Test Case 5
Input 1 2
5000 8000
1
50000
3
7000 9000 5000
2
12000 10000
4
23000 1200 0 3400
Test Case 13000
Output 1 50000
21000
22000
27600
Test Case 2
Input 2 4
1200 1000 50000 18000
6
323251
Test Case 70200
Output 2 16
Test Case 3
Input 3 4
12000 10000 5000 8000
2
3000 2000
3
7000 9000 5000
The built-in function, round(number, count), returns a floating point number that
is a rounded version of the specified number, with the specified number of
decimals (count). You can use this function in this problem.
Input Format First line contains the value of N, followed by N pairs of lines. The first line of
each pair contains the value of M and the second line of each pair contains space
separated M integers, denoting the marks of each student.
Output N lines, each having M space separated values.
Format
Sample Input 3
1 3
12 14 16
4
11 13 18 19
6
12 14 16 18 20 13
Sample 16 12 42 14.0
Output 1 19 11 61 15.2
20 12 93 15.5
Test Case 3
Input 1 4
10 18 30 34
5
11 10 18 10 20
5
12 22 19 18 22
Test Case 34 10 92 23.0
Output 1 20 10 69 13.8
22 12 93 18.6
Test Case 4
Input 2 1
10
2
55 67
5
12 16 17 20 21
6
21 12 33 34 56 78
Test Case 10 10 10 10.0
Output 2 67 55 122 61.0
21 12 86 17.2
78 12 234 39.0
Test Case 2
Input 3 5
50 45 60 55 70
3
90 95 100
Test Case 70 45 280 56.0
Output 3 100 90 285 95.0
Test Case 2
Input 4 4
30 30 30 30
2
99 99
Test Case 30 30 120 30.0
Output 4 99 99 198 99.0
14
Marks Sum of Top 5 and Last 5
You are given marks of some students. Print the sum of the marks of the top 5
students, and the marks of last 5 students in decreasing order.
Input Format The first line contains the value of N and the next line has N space separated
integers.
Output First line containing an integer value and second line contains 5 integer
Format numbers.
Sample Input 8
1 50 30 60 55 75 85 65 45
Sample 340
Output 1 60 55 50 45 30
Test Case 17
Input 1 0 12 0 14 1 14 1 16 45 23 10 0 25 27 16 18 21
Test Case 141
Output 1 11000
Test Case 12
Input 2 98 34 1 23 56 0 12 7 10 23 45 78
Test Case 311
Output 2 12 10 7 1 0
15.
Swap K-Blocks
Given an array of N integers and a positive integer K. Swap every K element with
the next K elements. N is a multiple of 2K. Use two nested loops.
Input First line of input contains the two integers denoting the value of N and K. The
Format second line contains N space separated integers.
Output N space separated integers in a single line.
Format
Sample 12 3
Input 1 2 3 4 5 6 7 8 9 10 11 12
Sample 4 5 6 1 2 3 10 11 12 7 8 9
Output
Test Case 10 5
Input 1 1 2 3 4 10 11 12 67 15 56
Test Case 11 12 67 15 56 1 2 3 4 10
Output 1
Test Case 84
Input 2 -1 2 -3 5 7 8 9 0
Test Case 7 8 9 0 -1 2 -3 5
Output 2
16
Remove Elements
17
Split The Array
Given an integer array having N elements. Find the first locations of the
minimum and maximum elements. Split the array into three parts from these
locations. Built another array by concatenating the second part, followed by the
first part, followed by the third part. Print the elements of this array in a single
line. It can be assumed that the minimum and maximum elements will not be the
same.
Input First line contains the value of N. The next line contains N space-separated
Format integers.
Output N space-separated integers.
Format
Sample 8
Input 24135976
Sample 13524976
Output
Sample 10
Input 2 2135917964
Sample 1352917964
Output 2
Sample 11
Input 3 42935817964
Sample 93584217964
Output 3
18
Compare Arrays
Given two arrays (A and B) having lengths N and M respectively. For each B[i]
print the count of elements from A, which is greater than B[i].
Input First line has two space separated integers denoting N and M. The second line
Format has N space separated integers. The third line has M space separated integers.
Output N space separated integers in a single line.
Format
Sample 57
Input 26139
5 1 8 7 0 4 12
Sample 2411520
Output
Test Case 57
Input 1 26169
5 1 1 7 0 4 12
Test Case 3441530
Output 1
Test Case 10 12
Input 2 1 2 3 4 5 6 7 8 9 10
2 22 2 2 2 2 2 8 2 13 2 12
Test Case 808888828080
Output 2
19
All Pairs with Sum K
Given an array having N integers and an integer K. Find all pairs of elements
from this array, such that their sum is K (brute force version of Two Sum
problem). Also discuss the complexity of your approach.
Input First line of input contains the value of N and K. The second line contains N space
Format separated integers.
Output Space separated elements of the pair. Each pair should go into a separate line.
Format
Sample 75
Input 8 -1 3 4 -3 2 1
Sample 8 -3
Output 32
41
Test Case 71
Input 1 8 -1 3 4 -3 2 1
Test Case -1 2
Output 1 4 -3
Test Case 10 2
Input 2 8 -1 3 4 -3 2 1 2 4 6
Test Case -1 3
Output 2
20
Next Greater Right Element
Given an array of N positive integers. For each element, print the first greater
element towards the right of the element. If no greater element is found, print 0.
Input First line of input has N and the next line has N space separated integers.
Format
Output N space separated integers in a single line.
Format
Sample 5
Input 42645
Sample 66050
Output
Test Case 6
Input 1 111144
Test Case 444400
Output 1
Test Case 1
Input 2 1
Test Case 0
Output 2
21
Maximum Profit
Given an array, P, holding N integers, where P[i] represents the price of a
particular stock on ith day. You are allowed to purchase and sell the stock only
once. Find out your maximum profit.
Input First line contains the value of N. The next line has N space separated integers.
Format
Output A single integer in a single line representing the maximum profit.
Format
Sample 5
Input 1 15231
Sample 4
Output 1
Test Case 6
Input 1 1 2 4 9 1 10
Test Case 9
Output 1
Test Case 7
Input 2 10 1 3 8 2 6 9
Test Case 8
Output 2
22
Maximum Subarray Sum
Given an array with N elements. Print the sum of the subarray having maximum
sum (brute force version of Kadane Algorithm). The elements of the array could
be positive, negative or zero. Also discuss the complexity of your approach.
Input Format First line contains the value of N. The next line has N space separated integers.
Output A single integer in a single line.
Format
Sample Input 7
1 8 -1 3 4 -3 2 1
Sample 14
Output 1
Test Case 12
Input 1
5 2 -6 1 4 2 -2 -3 7 2 11 -14
Test Case 23
Output 1
Test Case 16
Input 2 5 2 -6 1 4 2 -2 -3 7 2 10 -14 -18 -2 -3 -4
Test Case 22
Output 2
—----------------------------------------------------------------------------------------------------------------------------
Assignment Questions -
Add an Integer
3 Read a number from the console, add 3 to it and print it.
Input The first line contains the number.
Format
Output A single integer.
Format
Sample 2
Input
Sample 5
Output
Sum of integers
5 Read four integers from the console and print their sum. The input will be a
single line containing the four integers, separated by single whitespaces.
Input Four integers in a single line separated by space.
Format
Output A single integer.
Format
Sample 2 8 9 12
Input
Sample 31
Output
Greater Average
6 You are given 3 numbers A, B, and C. Determine whether the average of A and B is
strictly greater than C or not?
NOTE: Average of A and B is defined as (A+B)/2. For example, average of 5 and 9
is 7, average of 5 and 8 is 6.5.
Input Single line of input contains three space separated integers.
Format
Output "YES" or "NO" without quotes.
Format
Sample 596
Input 1
Sample YES
Output 1
For example, 98765, 10000, and 71023 are valid phone numbers, while 04123,
9231, and 872310 are not.
Alex went to a store and purchased N items, where the cost of each item is Y.
Determine whether the total bill is equivalent to a valid phone number.
Input The first line of input will consists of two space-separated integers N and X — the
Format number of items Alex bought and the cost per item.
Output For each test case, output on a new line, YES, if the total bill is equivalent to a valid
Format phone number and NO otherwise.
Sample 25 785
Input 1
Sample YES
Output 1
String Validation
8 Given a string S, determine if it contains both the characters '&' and '#' and the
length of the string is even. If both conditions are satisfied, print 'YES';
otherwise, print 'NO’.
Input Single line input string
Format
Output "YES" or “NO”.
Format
Sample abc&def#
Input 1
Sample YES
Output 1
Adding first-2 and last element-2 of list
9 Given N integers. Find the sum of the first 2 elements and last 2 elements in
separate lines. You can assume that N >= 4.
Input First line contains N. The next line contains the N space separated integers.
Format
Output Two integer in two different line.
Format
Sample 18
Input 1 2 3 4 5 6 7 8 9 10 12 13 15 21 22 45 90 100
Sample 3
Output 190
10 Given a list of N positive integers. You need to find out the count of odd and even
integers. If the count of odd integers are greater than the count of even integers,
print "Odd" (without quotes). If the count of even integers are greater than the
count of odd integers, print "Even" (without quotes). Print "Tie" (without quotes)
if count of odd and even integers are equal.
Input Two lines of input. First line contains an integer N, represting the total number of
Format integers. Second line of input contains N space separated integers.
Output Single string in single line.
Format
Sample 5
Input 1 10 24 3 37 38
Sample Even
Output 1
The built-in function, round(number, count), returns a floating point number that
is a rounded version of the specified number, with the specified number of
decimals (count). You can use this function in this problem.
Input First line contains the value of N, followed by N pairs of lines. The first line of each
Format pair contains the value of M and the second line of each pair contains space
separated M integers, denoting the marks of each student.
Output N lines, each having M space separated values.
Format
Sample 3
Input 1 3
12 14 16
4
11 13 18 19
6
12 14 16 18 20 13
Sample 16 12 42 14.0
Output 1 19 11 61 15.2
20 12 93 15.5
15 You are given two strings S1 and S2 and a number N. Insert S2 in S1 after every N
characters (see sample input). Print the modified String. Assume 0 < N < len(S1)
Input Three lines of Input. First line contains the string S1. The second line contains the
Format string S2. And the third line contains the number N.
Output A string in a single line.
Format
Sample quick fox
Input 1 #
2
Sample qu#ic#k #fo#x
Output 1
int main(){
int n,k;
cin>>n>>k;
vector<int> arr(n);
for(int i = 0; i<n; i++) cin>>arr[i];
cout<<(fun(arr, n, k)? "YES":"NO");
}
Two Sum-2
Problem Two Sum -1
Sum Equals to Sum
Problem
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> arr(N);
for (int i = 0; i < N; i++) cin >> arr[i];
cout << (fun(arr, N) ? "YES" : "NO");
return 0;
}
uncommon words
Problem
#include<bits/stdc++.h>
using namespace std;
stringstream s1(str1);
stringstream s2(str2);
unordered_map<string, int> freq;
string word;
vector<string> temp, result;
for(auto i: temp) {
if(freq[i] == 1) result.push_back(i);
}
return result;
}
int main() {
string s1, s2;
getline(cin, s1);
getline(cin, s2);
vector<string> result = fun(s1, s2);
if([Link]()){
for (auto &r : result) cout << r << " ";}
else
cout<< -1;
}
Majority element
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<<fun(arr, n);
}
Most frequent even
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> arr(n);
for(auto &i : arr)
cin >> i;
cout << fun(arr, n);
}
Find lucky Integer
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<<fun(arr, n);
}
Count pairs with abs diff k-1
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<int> arr(n);
for(auto &i : arr)
cin >> i;
cout << fun(arr, n, k);
}
count pairs with abs diff - 2
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<int> arr(n);
for(auto &i : arr)
cin >> i;
cout << fun(arr, n, k);
}
Map
Sliding window
K length Window Max-Sum
Problem K length window max sum
C++ #include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin>>n>>k;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<<fun(arr, n, k);
}
Python def fun(arr, n, k):
start = 0
sum = 0
result = float('-inf')
for end in range(0, n):
sum += arr[end]
if(end-start+1) == k:
result = max(result, sum)
sum -= arr[start]
start += 1
return result
n, k = map(int, input().split())
arr = list(map(int, input().split()))
print(fun(arr,n,k))
Java
import [Link];
import [Link];
import [Link];
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new
InputStreamReader([Link]));
[Link](fun(arr, n, k));
}
}
Size k subarray with given avg
Problem Size K subarrays with given average
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k, t;
cin>>n>>k>>t;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<<fun(arr, n, k, t);
}
First Negative Integer
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin>>n>>k;
vector<int> arr(n);
vector<int> result;
for(auto &i: arr) cin>>i;
fun(arr, result, n, k);
for(auto i: result) cout<<i<<" ";
}
Max vowels in a substring
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin>>n>>k;
string s;
cin>>s;
cout<<fun(s, n, k);
}
K consecutive black blocks
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin>>n>>k;
string s;
cin>>s;
cout<<fun(s, n, k);
}
Obtain Max Points
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin>>n>>k;
vector<int> arr(n);
for(auto &i: arr) cin>> i;
int sum = accumulate([Link](), [Link](), 0);
if(k == n) cout<< sum;
else
cout<<sum - fun(arr, n, n-k);
}
**permutation in a string
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n1, n2; cin>>n1>>n2;
string s1, s2; cin>>s1>>s2;
cout<<(fun(s1, s2, n1, n2)?"True":"False");
}
all anagram
#include<bits/stdc++.h>
using namespace std;
int main(){
int n1, n2; cin>>n1>>n2;
string s1, s2; cin>>s1>>s2;
vector<int> result = fun(s1, s2, n1, n2);
if([Link]()){
for(auto i: result)
cout<<i<<" ";
}
else cout<<-1;
}
Longest subarray of 1's
Start of variable length SW
Problem
Best way-
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<< fun(arr, n);
}
Another Approach
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<< fun(arr, n);
}
Longest subarray of 1 - 2
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<<fun(arr, n)-1;
}
Longest subarray of 1s with k swaps
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k; cin>>n>>k;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<<fun(arr, n, k);
}
Unique length k substring
Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k; cin>>n>>k;
string s; cin>>s;
cout<<fun(s, n, k);
}
collect fruits
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> trees(n);
for(auto &i: trees) cin>>i;
cout<<fun(trees, n);
}
Longest substring with distinct words
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<string> words(n);
for(string &i: words) cin>>i;
cout<<fun(words, n);
}
Not all flavors
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k; cin>>n>>k;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<<fun(arr, n, k);
}
Prefix Sum
Running sum of 1d array
Prefix Sum, total - 13Q
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
vector<int> result = fun(arr, n);
for(auto i: result) cout<<i<<" ";
}
Find Pivot Index
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
cout<<fun(arr, n);
}
Largest Subarray with sum K
Tab 32
Tab 33
Tab 34
Tab 35
Tab 36
Tab 37
Tab 38
Tab 39
q25to50
25. Mod 3
#include<bits/stdc++.h>
using namespace std;
int main(){
int l, h;
cin>>l>>h;
int count = 0;
for(int i = l; i<=h; i++){
if(i%3 == 0){
int sum = 0;
int num = i;
while(num > 0){
int d = num%10;
sum += d;
num = num/10;
}
if((sum % 2) == 0) count++;
}
}
cout<<count;
}
26. Single digit number
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin>>n>>k;
int singledigit = fun(n);
cout<<fun(singledigit*k);
}
27. Even sum primes
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b; cin>>a>>b;
int count = 0;
for(int i = a; i <= b; i++){
if(isPrime(i) && evenDigitSum(i)) count++;
}
cout<<count;
}
int main(){
int lower, upper;
cin>>lower>>upper;
bool flag = false;
for(int i = lower; i <= upper; i++){
if(isArmstrong(i)){
if(!flag) flag = true;
cout<<i<<" ";
}
}
if(!flag) cout<<-1;
}
int main(){
int n; cin>>n;
for(int i = 0; i<=n; i++){
if(i < 10) cout<<i<<" ";
else{
if(isJumping(i)) cout<<i<<" ";
}
}
}
30. Nth tribonacci number
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
cout<<tribo(n);
}
31. Prime Multiplied Series
int main(){
int n; cin>>n;
vector<int> arr(n);
for(auto &i: arr) cin>>i;
for(int i = 0; i < n; i++){
int count = 0;
for(int j = 0; j < n; j++){
if(arr[j] > arr[i]) count++;
}
cout<<count+1<<" ";
}
}
33.
34.
35.
36.