Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequent Sums #307

Open
HarshDutt17 opened this issue Oct 14, 2021 · 2 comments
Open

Frequent Sums #307

HarshDutt17 opened this issue Oct 14, 2021 · 2 comments
Labels
CP Competitive Programming good first issue Good for newcomers hacktoberfest-accepted Hacktoberfest accepted issues Medium

Comments

@HarshDutt17
Copy link
Collaborator

Mr Chaggan Lal has just learned the maximum subarray sum problem. And while thinking about the solution, he came up with a new problem, the maximum frequent subarray sum problem.

In this problem, you will be given an array A of N integers. You have to choose a non-empty subarray with the maximum possible score. The score of a subarray is calculated as

score(l,r)=(Al+⋯+Ar)⋅(occurrences)

Here, occurrences is the number of occurrences of that subarray in A.

Now Chaggan can't solve this problem as he is aged, so please help him solve it and in return you will get blessings of Chaggan Lal for a Placement😉

Input

  • The first line contains an integer T, the number of test cases. Then the test cases follow.
  • The first line of each test case contains an integer n, the size of the array.
  • The second line contains n integers A1,…,AN.

Output

  • For each test case, output the maximum possible score in a new line.

Sample Input
2
6
10 8 -20 5 5 5
10
-5 1 7 -1 2 -4 10 0 -11 3

Sample Output
20
15

Explanation

In the first test case, the maximum score is attained by subarray [5,5], its score is (5+5)⋅2=20 since it occurs twice in A.

In the second test case, the maximum score is attained by both subarrays [1,7,−1,2,−4,10] and [1,7,−1,2,−4,10,0]. Both have sum 15 and occur once, so their scores are 15⋅1=15.

@HarshDutt17 HarshDutt17 added CP Competitive Programming good first issue Good for newcomers hacktoberfest-accepted Hacktoberfest accepted issues Medium labels Oct 14, 2021
@HarshDutt17 HarshDutt17 assigned suman203 and unassigned suman203 Oct 14, 2021
@PEC-CSS PEC-CSS deleted a comment from suman203 Oct 28, 2021
@swarupsahu08
Copy link

swarupsahu08 commented Oct 8, 2024

Hey @Gauravsharma-20, @HarshDutt17 can the code be written in java language and can you assign me this issue to solve the problem

@iammarvin7
Copy link

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CP Competitive Programming good first issue Good for newcomers hacktoberfest-accepted Hacktoberfest accepted issues Medium
Projects
None yet
Development

No branches or pull requests

4 participants