1.

Below is the code to find maximum subarray sum, with errors (which may results to wrong output) in the statement which is commented on right half after code statement. You need to choose the correct option for which corresponding statement is wrong.#include<iostream>using namespace std;// Function to calculate maximum subarray sumint maxSubArraySum(int a[ ], int size){int max_so_far = a[0];int curr_max = a[0];for (int i = 1; i < size; i++){curr_max = max(a[i], curr_max); // statement 1max_so_far = max(max_so_far, curr_max); // statement 2}return max_so_far;}/* Driver program to test maxSubArraySum */int main(){int a[] = {-2, -3, 4, -1, -2, 1, 5, -3};int n = sizeof(a)/sizeof(a[0]);int max_sum = maxSubArraySum(a, n);cout << "Maximum contiguous sum is " << max_sum;return 0;}(A) Statement 1 and statement 2 both.(B) Statement 1 only.(C) Statement 2 only.(D) Neither statement 1 nor statement 2.

Answer»


Discussion

No Comment Found

Related InterviewSolutions