Posted: 26 Nov, 2020
Ninjas has been given an array. He wants to find a subarray such that the sum of all elements in the subarray is maximum.
Subarray 'A' is greater than sub-array 'B' if sum(A) > sum(B). If two sub-array have the same maximum sum, then output the subarray that has a larger length.
A subarray means a contiguous part of an array. For example, In 'arr' = [1, 2, 3, 4], [1, 2], [2, 3, 4] are the contiguous subarry but [1, 3, 4] is not a subarray.
More than one sub-array can have a maximum sum, in that case, output any.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. The first line of each test case contains a single integer ‘N’ denoting the size of the array. The second line of each test case contains ‘N’ space-separated integers denoting the elements of the array.
For each case, If the returned subarray is correct then print 1, else print 0. The output of each test case will be printed in a separate line.
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
1 <= T <= 5 1 <= N <= 1000 -99 <= |arr| <= 99 Time limit: 1 sec.
Best time to buy and sell stock
Posted: 2 Sep, 2022
Best time to buy and sell stock II
Posted: 5 Sep, 2022
Ninja And The Class Room
Posted: 19 Sep, 2022
Posted: 21 Oct, 2022
Find The Single Element
Posted: 30 Oct, 2022