✅✅ USING TWO POINTERS || BEATS 100% || C++ CODE ✅✅
IntuitionThe problem requires counting the pairs in an array whose sum is strictly less than the target. By sorting the array and applying a two-pointer techniq
# Intuition
The problem requires counting the pairs in an array whose sum is strictly less than the target. By sorting the array and applying a two-pointer technique, we can efficiently count valid pairs without checking each pair.

# Approach
1. **Sort the array**: Sorting helps in efficiently finding pairs that sum to less than the target.
2. **Two-pointer technique**:
   - Initialize two pointers, `i` at the start and `j` at the end of the array.
   - If `nums[i] + nums[j] < target`, all pairs from `i` to `j` are valid, so we count them by adding `j - i` to the result.
   - Move the left pointer `i` to the right.
   - If the sum is greater than or equal to the target, move the right pointer `j` left to decrease the sum.

# Complexity
- **Time complexity**: $$O(n \log n)$$, due to sorting the array.
- **Space complexity**: $$O(1)$$, as we only use a few variables.

# Code
```cpp []
class Solution {
public:
    int countPairs(vector<int>& nums, int target) {
        sort(nums.begin(),nums.end());
        int i=0,j=nums.size()-1,count=0;
        while(i<j){
            int sum=nums[i]+nums[j];
            if(sum<target){
                count+=j-i;
                i++;
            }
            else 
                j--;
        }
        return count;
    }
};
```
![upvote.png](https://assets.leetcode.com/users/images/90822e9e-7566-45e0-b214-0b0492f3cd9a_1738399512.045182.png)

['Array', 'Two Pointers', 'Sorting', 'C++']