TCS - CodeVita - Coding Arena Page6
TCS - CodeVita - Coding Arena Page6
Arpan Mitra
Guidelines
ONLINE EDITOR (F)
Coding Area Max Sum
Public Testcase Problem Description
Submissions
Two friends A and B are playing with an array of integers. They both agree
Private Testcase upon the operations to be performed on the array but differ on choice of
Submissions window size to perform the said operations.
Feedback Form · After performing the addition operation, it is mandatory to skip the next
element in the array.
Graphs · The goal is to achieve maximum sum by choosing appropriate elements
in the array.
Zone 1 Statistics
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
· We choose to skip element 2 because the next three values are also
higher than 2.
https://www.tcscodevita.com/main_page.jsp 1/4
8/15/2020 TCS: CodeVita - Coding Arena
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
Input
First line contains three space separated integers N and W and D
respectively, which denote
N - size of array
W - window size
D - difference
Output
If B wins, print “Right <absolute difference>”
Time Limit
1
https://www.tcscodevita.com/main_page.jsp 2/4
8/15/2020 TCS: CodeVita - Coding Arena
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
https://www.tcscodevita.com/main_page.jsp 3/4
8/15/2020 TCS: CodeVita - Coding Arena
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.
CodeVita FAQs
About CodeVita
Privacy Policy
Careers
https://www.tcscodevita.com/main_page.jsp 4/4