"100% Optimal Brute Force Solution for Counting Pairs with Sum Less than Target 💯"
IntuitionWhen I first approached this problem, I realized that we need to count all pairs of numbers in the array whose sum is less than the given target. The s
# Intuition
When I first approached this problem, I realized that we need to count all pairs of numbers in the array whose sum is less than the given target. The simplest way to achieve this is by iterating through all possible pairs and checking their sum.

# Approach
To solve the problem:
1. Use two nested loops to iterate through all pairs of numbers `(i, j)` where `i < j`.
2. For each pair, check if the sum of the two numbers is less than the given `target`.
3. If the condition is satisfied, increment a counter.
4. Return the counter as the final result.

This is a brute-force approach and is straightforward to implement. However, it may not be efficient for large arrays due to its quadratic time complexity.

# Complexity

### Time Complexity:
$$O(n^2)$$  
- The outer loop runs \(n-1\) times, and for each iteration of the outer loop, the inner loop runs \(n-i-1\) times.  
- This results in a total of approximately \(\frac{n(n-1)}{2}\), which is \(O(n^2)\).

### Space Complexity:
$$O(1)$$  
- No additional data structures are used. The solution only uses a variable `ans` to store the count.

# Code
```cpp
class Solution {
public:
    int countPairs(vector<int>& nums, int target) {
        int ans = 0; // Counter for the number of valid pairs

        // Outer loop to fix the first element
        for (int i = 0; i < nums.size() - 1; i++) {
            // Inner loop to fix the second element
            for (int j = i + 1; j < nums.size(); j++) {
                // Check if the pair sum is less than the target
                if (nums[i] + nums[j] < target) {
                    ans++; // Increment the counter
                }
            }
        }

        return ans; // Return the total count of valid pairs
    }
};

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