D) String Pair: Problem Description
D) String Pair: Problem Description
Problem Description
One person hands over the list of digits to Mr. String, But Mr. String understands only
strings. Within strings also he understands only vowels. Mr. String needs your help to find
the total number of pairs which add up to a certain digit D.
Take all digits and convert them into their textual representation
Next, sum up the number of vowels i.e. {a, e, i, o, u} from all textual representation
Now, once digit D is known find out all unordered pairs of numbers in input whose sum is
equal to D. Refer example section for better understanding.
Constraints
1 <= N <= 100
Number 100, if and when it appears in input should be converted to textual representation
as hundred and not as one hundred. Hence number of vowels in number 100 should be 2
and not 4
Input
First line contains an integer N which represents number of elements to be processed as
input
Output
Lower case representation of textual representation of number of pairs in input that sum up
to digit D
Note: - (If the count exceeds 100 print "greater 100")
Time Limit
1
Examples
Example 1
Input
12345
Output
one
Explanation
Now from given list of number {1,2,3,4,5} -> find all pairs that sum up to 9.
Upon processing this we know that only a single unordered pair {4, 5} sum up to 9. Hence
the answer is 1. However, output specification requires you to print textual representation of
number 1 which is one. Hence output is one.
Note: - Pairs {4, 5} or {5, 4} both sum up to 9. But since we are asking to count only
unordered pair, the number of unordered pair is this combination is only one.
Example 2
Input
742
Output
zero
Explanation
Since no pairs add up to 5, the answer is 0. Textual representation of 0 is zero. Hence output
is zero.
E) Max Sum
Problem Description
Two friends A and B are playing with an array of integers. They both agree upon the
operations to be performed on the array but differ on choice of window size to perform the
said operations.
· After performing the addition operation, it is mandatory to skip the next element in the
array.
· The goal is to achieve maximum sum by choosing appropriate elements in the array.
A wants X to be W, while B wants X to be (W + D). This is the only difference that they have.
Your task is to find out who wins. Winner is the person whose sum is higher.
The inputs that will be provided are values of elements of array, value of W and value of D.
Example:
Array: 4 5 6 1 2 7 8 9
Output: 39
Explanation
· Since one addition operation is complete, we have to skip one element which is 1.
· We choose to skip element 2 because the next three values are also higher than 2.
· The max sum thus obtained is 39.
· Since one addition operation is complete, we have to skip one element which is 1.
· Now we choose to pick element 2 because we can skip element 3 and still pick up the next 3
values viz 7, 8, 9.
· Note that we picked up only one element in second selection since constraint is only on
maximum number to be chosen, not minimum.
The above examples illustrate the game with a fixed window size of W. Since B prefers to play
the same game with the size of W+D, the steps will remain the same but the max sum output
may be different. Print different output depending on whether A wins, B wins or it’s a tie.
Constraints
0 <= N <= 10 ^ 5
5 <= W <= 10 ^ 5
0 < (W + D) <= N
N - size of array
W - window size
D - difference
Second line contains of N space separated integers denoting the elements of the array
Output
If B wins, print “Right <absolute difference>”
Time Limit
1
Examples
Example 1
Input
8 5 -2
45612789
Output
Wrong 2
Explanation
A will maximize the sum of elements of the array using window size 5. Whereas B will
maximize the sum of elements of the array using window size 3 (5-2).
Using logic as depicted above A will get the max sum as 41 and B will get the max sum as 39.
The absolute difference is 41 - 39 = 2.
Example 2
Input
922
456123789
Output
Right 10
Explanation
A will maximize the sum of elements of the array using window size 2. Whereas B will
maximize the sum of elements of the array using window size 4 (2+2).
Using logic as depicted above A will get the max sum as 33 and B will get the max sum as 43.
The absolute difference is 43 - 33 = 10.
Example 3
Input
10 9 -3
4563237892
Output
Explanation
A will maximize the sum of elements of the array using window size 9. Whereas B will
maximize the sum of elements of the array using window size 6 (9-3).
Using logic as depicted above A will get the max sum as 47 and B will get the max sum as 47.
The absolute difference is 47 - 47 = 0.
Working from left to right, choose the smallest split for the first substring that still allows the
remaining word to be split into 2 palindromes.
Similarly, choose the smallest second palindromic substring that leaves a third palindromic
substring.
If there is no way to split the word into exactly three palindromic substrings, print
"Impossible" (without quotes). Every character of the string needs to be consumed.
After finding 3 palindromes using above instructions, if any character of the original string
remains unconsumed.
Constraints
1 <= the length of input sting <= 1000
Input
First line contains the input string consisting of characters between [a-z].
Output
Print 3 substrings one on each line.
Time Limit
1
Examples
Example 1
Input
nayannamantenet
Output
nayan
naman
tenet
Explanation
The original string can be split into 3 palindromes as mentioned in the output.
However, if the input was nayanamantenet, then the answer would be "Impossible".
Example 2
Input
aaaaa
Output
aaa
Explanation
The other ways to split the given string into 3 palindromes are as follows -
Example 3
Input
aaaabaaaa
Output
aaabaaa
Explanation
The other ways to split the given string into 3 palindromes are as follows -
Since we want to minimize the length of the first palindromic substring using left to right
processing, the correct way to split is [a, aaabaaa, a].