Maximum Sub array Sum which datatype to be used for multiple testcases

MAXIMUM SUBARRAY SUM
You are given a one dimensional array that may contain both positive and negative integers, find the sum of contiguous subarray of numbers which has the largest sum. For example, if the given array is {-2, -5, 6, -2, -3, 1, 5, -6}, then the maximum subarray sum is 7.

Input Format:
The first line consists of number of test cases T. Each test case consists of N followed by N integers.
Sample Input
2
4
1 2 3 4
3
-10 5 10
here I know the code for maximum subarray sum and if we take no. of test cases then how I should store multiple arrays for multiple testcases.

@pratyushgoel2 Hey Pratyush rather than declaring multiple array you can simply declare one array and can use that array in every testcase. For example In Maximum subarray Problem you can declare int arr[100000] and use this in every test case although there is also vector stl but it will be covered in the further videos.

but how can i differentiate all testcases and their result if i uses only 1 array.

@pratyushgoel2 hey pratyush here is the code which help you to understand how to process a single array for multiple test case
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t- -){
int n;
cin>>n;
int arr[1000];
for(int i=0;i<n;i++){
cin>>arr[i];
}
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}

}

1 Like

@pratyushgoel2 Hey Pratyush you can refer this code.

@pratyushgoel2 Hey Pratyush, I hope We’ve cleared your doubt. Please mark this doubt as resolved and rate us on the basis of your experience. Rating option is just below where you mark this doubt as resolve. Your feedback is very important. It helps us to improve our platform and hence provide you the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.