From 0035a5bfe57c3c2b303321a8b25834f9e5ce9791 Mon Sep 17 00:00:00 2001 From: Sumit-Rajak99 Date: Thu, 16 Oct 2025 21:57:26 +0530 Subject: [PATCH] pair --- hello.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 hello.cpp diff --git a/hello.cpp b/hello.cpp new file mode 100644 index 0000000..99cd931 --- /dev/null +++ b/hello.cpp @@ -0,0 +1,29 @@ + #include +using namespace std; + +class Solution { +public: + bool hasPairWithSum(vector& 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 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; +}