Instead of using O(2N).
I have solved it in O(N), here is my approach
class Solution {
public:
int pairsum(vector &arr) {
// code here
int greater1=arr[0];
int greater2=arr[1];
int n=arr.size();
for(int i=2;i
Yes, so instead of using two for loops, you have written multiple if else condition inside one for loop. So yeah that's great, and thanks for your kind words.😀
Let's Connect 🤝 :
LinkedIn : www.linkedin.com/in/rochak-vyas17/
Code :-
class Solution {
public:
int pairsum(vector &arr) {
int n=arr.size();
int maxi=INT_MIN;
for(int i=0;imaxi){
maxi=arr[i];
}
}
int secmaxi=INT_MIN;
for(int i=0;isecmaxi&&arr[i]