C++ solution || Two Pointer Approach
Intuition\n Describe your first thoughts on how to solve this problem. \nSo the brute force approach would be to check every pair possible and to check the sum 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSo the brute force approach would be to check every pair possible and to check the sum if it is coming out to be less than the target.That solution is also acceptable here due to the given constraints.\n\nBut given the fact that we can sort the array in nlogn it will give us an advantage for higher array size.we must use this advantage to reduce the number of comparisons we are gonna make and we use two pointer approach which gives us more control over the number of comparisons we are going to make.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe use two pointer approach which will be better for inputs with higher value of n:number of elements.\n\nSo we start with sorting the array for using two pointers\nwe keep our first pointer at the beginning of the sorted array while the end point at the end as the name suggests\n\nwe compare the sum of start and end elemets to what our pointer points to if the sum comes out to be less than our target(which is required)we know that since we sorted the array in ascending order now all the elements right from the end start are decreasing in nature so if we got the sum less than target at the element to which end is pointing all elements right from there till start will also lead to a sum less than target hence we update our answer variable\nanswer+=(end-start).now we increment our start pointer to next the next element similarly we check the sum of start and end.\nif it is less than target we repeat what we did earlier, if it comes out to be greater or equal to target than we know that by decreasing end point (end--) we can decrease our sum so that we get the desired result once it becomes less than target again answer is incremented with end-start.\n\nthis will ensure all the proper comparisons ignoring useless comparisons.\n\n# Complexity\n- Time complexity:\nso sorting the array take O(nlogn)\nthat is out TC\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int countPairs(vector<int>& nums, int target) {\n       //solving this using two pointer approach\n       sort(nums.begin(),nums.end());\n       int answer=0;\n       int start=0;\n       int end=nums.size()-1;\n\n       while(start<end)\n       {\n        if(nums[start]+nums[end]<target)\n        {\n            answer+=(end-start);\n            start++;\n            \n        }\n        else\n        {\n            end--;\n        }\n       }\n       return answer;\n        \n    }\n};\n```
['C++']