C++ || 99% ✔ || Optimal || Beginner Friendly
\n Optimal Solution:\n\n\nclass Solution {\npublic:\n    vector<vector<int>> findPrimePairs(int n) {\n        vector<vector<int>> primePairs;\n        if (n < 4
\n* **Optimal Solution:**\n\n```\nclass Solution {\npublic:\n    vector<vector<int>> findPrimePairs(int n) {\n        vector<vector<int>> primePairs;\n        if (n < 4) {\n            return primePairs;\n        }\n\n        // Check for even numbers\n        if (n % 2 == 0) {\n            int x = n / 2;\n            if (isPrime(x) && isPrime(n - x)) {\n                primePairs.push_back({x, n - x});\n            }\n        }\n\n        // Check for odd numbers\n        for (int x = 2; x <= n / 2; ++x) {\n            int y = n - x;\n            if (isPrime(x) && isPrime(y) && x < y) {\n                primePairs.push_back({x, y});\n            }\n        }\n\n        sort(primePairs.begin(), primePairs.end());\n        return primePairs;\n    }\n\nprivate:\n    bool isPrime(int x) {\n        if (x < 2) {\n            return false;\n        }\n        for (int i = 2; i * i <= x; ++i) {\n            if (x % i == 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n};\n\n```\n\n* **TLE: BruteForce approach**\n\n```\nclass Solution {\npublic:\n    vector<vector<int>> findPrimePairs(int n) {\n        vector<vector<int>> primePairs;\n        for (int x = 2; x <= n / 2; ++x) {\n            int y = n - x;\n            if (isPrime(x) && isPrime(y)) {\n                primePairs.push_back({x, y});\n            }\n        }\n        return primePairs;\n    }\n\nprivate:\n    bool isPrime(int x) {\n        if (x < 2) {\n            return false;\n        }\n        for (int i = 2; i <= sqrt(x); ++i) {\n            if (x % i == 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n};\n```\n\n![image](https://assets.leetcode.com/users/images/322e34c3-9dd1-4ec4-946c-788e892db3d4_1688274024.5974.gif)\n
[]