Two pointer approach | Easy to understand.....
\n\n# Code\n\nclass Solution {\npublic:\n    int countPairs(vector<int>& nums, int target) {\n        sort(nums.begin() , nums.end());\n        \n        int cn
\n\n# Code\n```\nclass Solution {\npublic:\n    int countPairs(vector<int>& nums, int target) {\n        sort(nums.begin() , nums.end());\n        \n        int cnt = 0;\n\n        int i = 0 , j = nums.size()-1;\n\n        while(i<j){\n            int val = nums[i]+nums[j];\n            if(val < target){\n                cnt += j-i;\n                i++;\n            }\n            else if(val >= target){\n                j--;\n            }\n            else i++;\n        }\n        \n        \n        \n        return cnt;\n    }\n};\n```
['C++']