This Problem can be solved in O(n^2) using sorting and two pointer approach .1) First sort the array -> nlogn2) In the outer loop we iterate for the RHS (a[k]) and in the inner loop we find the LHS using two pointer approach.3) outer loop takes O(n) and the inner loop also takes linear timeSo the overall time complexity is nlogn+n^2 which is O(n^2)Code:sort(a,a+n) --> //sorting the array initiallyfor(int k=n;k>=1;k—) // Outer loop{int i =1, int j=k-1 : // 2 pointersWhile(i<j){ // inner loopint Sum=a[i]+a[j];If(Sum==a[k])Found a pair, i++;Else if(sum<a[k])i++; // increment i pointer so that sum approaches a[k]Elsej—; // reduce j pointer so that sum approaches a[k]}}