2 APPROACHES || EASIEST INTUITIVE APPROACH USING SORTING ||
Approach\nUse two pointer method and increase the count by the diff b/w the two pointers because we can find j - i pairs with element at index i and every eleme
# Approach\nUse two pointer method and increase the count by the diff b/w the two pointers because we can find j - i pairs with element at index i and every element till jth index.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nlog(n)) + O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code Approach 1\n```\nclass Solution {\npublic:\n    int countPairs(vector<int>& nums, int target) {\n        sort(nums.begin(),nums.end());\n        int i = 0, j = nums.size() - 1, cnt = 0;\n        while(i < j){\n            if(nums[i] + nums[j] < target){\n                cnt += (j - i);\n                i++;\n            }\n            else\n                j--;\n        }\n        return cnt;\n    }\n};\n```\n# Approach 2\n# Complexity\n- Time complexity: O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code Approach 2\n```\nclass Solution {\npublic:\n    int countPairs(vector<int>& nums, int target) {\n        int cnt = 0, n = nums.size();\n        for(int i = 0; i < n; i++){\n            for(int j = i + 1; j < n; j++){\n                if(nums[i] + nums[j] < target)cnt++;\n            }\n        }\n        return cnt;\n    }\n};\n```
['Sorting', 'C++']