Find the largest pair sum in an unsorted array | GeeksforGeeks

preview_player
Показать описание

This video is contributed by Parikshit Kumar Pruthi

Please Like, Comment and Share the Video among your friends.

Also, Subscribe if you haven't already! :)
Рекомендации по теме
Комментарии
Автор

I like the way he says Hiiii Friendsss

lakhdeepsingh
Автор

int findLargestSumPair(int arr[], int n)
{
// Initialize first and second largest element
int first, second;
if (arr[0] > arr[1])
{
first = arr[0];
second = arr[1];
}
else
{
first = arr[1];
second = arr[0];
}

// Traverse remaining array and find first and second largest
// elements in overall array
for (int i = 2; i<n; i ++)
{
/* If current element is greater than first then update both
first and second */
if (arr[i] > first)
{
second = first;
first = arr[i];
}

/* If arr[i] is in between first and second then update second */
else if (arr[i] > second && arr[i] != first)
second = arr[i];
}
return (first + second);
}

wecan
Автор

Using max heap would reduce the time complexity to O(logn)

KaranSehgal
Автор

Before giving solution give some example question atleast... It will be helpful.

ahishnar