C++ 🧠 || Beats 100%🔥|| 3 Lines Code💀💯|| EasyPizyy🔥💯
IntuitionThe problem requires counting pairs (i, j) such that nums[i] + nums[j] < target. The simplest way to approach this is by checking all possible pairs in
![Screenshot 2025-03-29 221011.png](https://assets.leetcode.com/users/images/fdf5f3c4-82a5-482c-91f0-90b9862a8a08_1743266559.3486977.png)

# Intuition
The problem requires counting pairs `(i, j)` such that `nums[i] + nums[j] < target`. The simplest way to approach this is by checking all possible pairs in the array.

# Approach
1. Use a **nested loop**:
   - Iterate over all elements with index `i`.
   - For each `i`, iterate over elements `j > i` to form pairs.
   - If `nums[i] + nums[j] < target`, increase the count.
2. Return the count after iterating through all valid pairs.

# Complexity
- **Time complexity**: $$O(n^2)$$  
  The solution involves two nested loops, iterating over all pairs `(i, j)`, leading to quadratic time complexity.
  
- **Space complexity**: $$O(1)$$  
  Only a few integer variables (`cnt`, `n`, `i`, `j`) are used, so the space complexity is constant.

# Code
```cpp
class Solution {
public:
    int countPairs(vector<int>& nums, int target) {
        int cnt = 0, n = nums.size();
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (nums[i] + nums[j] < target) cnt++;
            }
        }
        return cnt;
    }
};
```
![upvote.jpeg](https://assets.leetcode.com/users/images/c1454fd8-2561-4b87-b0d3-e7970de121a2_1743266532.3445368.jpeg)

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