Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I NEED HELP IN THIS QUESTION .... DON'T USE HASHMAP OR MAP YOU CAN USE ARRAY OR ARRAYLIST Given a set A of N integer

I NEED HELP IN THIS QUESTION ....

DON'T USE HASHMAP OR MAP YOU CAN USE ARRAY OR ARRAYLIST

Given a set A of N integer numbers, you are to find maximum sum of any subset of consecutive numbers in A.

Input The first line of input contains a single integer T, (1 T 100), which is the number of test sets that follow. Each test set starts with N (1 N 100,000) on a line by itself. Then Nlines follow, each containing an integer within the range [-1000, +1000].

Output For each test set, you should output the maximum sum as defined above.

Sample

Input

output

2 7 10 3 -20 20 3 -8 3 5 -10 3 -3 2 -98

23 3

Explanation of the inputs and outputs:

The first test case contains 7 numbers : 10, 3, -20, 20, 3, -8, 3.

The maximum sum of any subset of consecutive integers in the set is 20 + 3 = 23. If you take any other sum, it will be smaller. For example, 10+3+ -20 + 20 + 3 = 16 etc.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions