1.

What is the time complexity of below code?// CPP program to find the maximum value// of i*arr[i]#include<bits/stdc++.h>using namespace std;int maxSum(int arr[], int n){// Sort the arraysort(arr, arr + n);// Finding the sum of arr[i]*iint sum = 0;for (int i = 0; i < n; i++)sum += (arr[i]*i);return sum;}// Driven Programint main(){int arr[] = { 3, 5, 6, 1 };int n = sizeof(arr)/sizeof(arr[0]);cout << maxSum(arr, n) << endl;return 0;}(A) O(N)(B) O(logN)(C) O(NlogN)(D) O(N*N)

Answer»


Discussion

No Comment Found

Related InterviewSolutions