Skip to content

Commit

Permalink
Added pairSum
Browse files Browse the repository at this point in the history
  • Loading branch information
theyashkishore committed Sep 19, 2022
1 parent 1e1b55b commit c39cd57
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Sheet400-C++/Arrays/pairSum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> pairSum(vector<int> &arr, int s){
vector<vector<int>> ans;

for(int i = 0; i < arr.size(); i++){
for(int j = i+1; j < arr.size(); j++){
if(arr[i] + arr[j] == s){
vector<int> temp;
temp.push_back(min(arr[i], arr[j]));
temp.push_back(max(arr[i], arr[j]));
ans.push_back(temp);
}
}
}

sort(ans.begin(), ans.end());
return ans
}

int main() {
int arr[100];
int size;
cin >> size;

for(int i = 0; i < size; i++){
cin >> arr[i];
}
cout << pairSum(arr, size) << endl;

}

0 comments on commit c39cd57

Please sign in to comment.