Skip to content
Open

pair #20

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
bool hasPairWithSum(vector<int>& arr, int target) {
int i = 0, j = arr.size() - 1;
while (i < j) {
int sum = arr[i] + arr[j];
if (sum == target) return true;
else if (sum < target) i++;
else j--;
}
return false;
}
}; // ✅ class खत्म होने के बाद semicolon ज़रूरी है

int main() {
vector<int> arr = {1, 2, 4, 7, 11, 15};
int target = 15;

Solution sol;
if (sol.hasPairWithSum(arr, target))
cout << "Pair Found!" << endl;
else
cout << "No Pair Found!" << endl;

return 0;
}