Which Test Case am i miising?
Test Case Missing
Can u pls help me in my code that which test case it is failing?
#include using namespace std; int maxCirArrSum (int *arr, int n){ if (n == 1){ return arr[0]; } int cnt = 0; for (int i = 0; i < n; i++){ if (arr[i] < 0){ cnt++; } } int sum = 0; for (int i = 0; i < n; i++){ arr[i] *= -1; sum += arr[i]; } //kadane’s algo int temp = arr[0]; int currSum = 0, maxSum = arr[0]; for (int i = 0; i < n; i++){ temp = max(temp, currSum); currSum += arr[i]; if (currSum < 0){ currSum = 0; } maxSum = max(maxSum, currSum); } int ans = -1 * (sum - maxSum); if (cnt == n){ return temp; } else{ return ans; } } int main() { int t; cin >> t; while (t != 0){ int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++){ cin >> arr[i]; } cout << maxCirArrSum(arr, n) << endl; t–; } return 0; }
already seen implemented the same…still missing one test case
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.