✅✅ 3 Liner Loop || Easy Solution
Approach1. Sorting and Two-Pointer Strategy
Sort the people array in ascending order.
Use two pointers:

i (lightest person) starts from the left.
j (heaviest p
# Approach

### **1. Sorting and Two-Pointer Strategy**
- **Sort the `people` array** in ascending order.
- Use two pointers:
  - `i` (lightest person) starts from the left.
  - `j` (heaviest person) starts from the right.

### **2. Greedy Pairing**
- Try to **pair the heaviest person (`people[j]`) with the lightest (`people[i]`)** if their sum ≤ `limit`.
- If they **fit in one boat**, move both pointers (`i++`, `j--`).
- If not, send the **heaviest person alone** (`j--`).
- **Increment the boat count** after each iteration.

# Complexity:
- **Time Complexity:** `O(N log N)` (due to sorting).
- **Space Complexity:** `O(1)` (only uses a few extra variables).

# Code
```cpp []
class Solution {
public:
    int numRescueBoats(vector<int>& people, int limit) {
        int n=people.size();
        sort(people.begin(),people.end());

        int i=0,j=n-1;
        int ans=0;

        while(i<=j){
            if(people[j]+people[i]<=limit) i++,j--;
            else j--;
            ans++;
        }
        return ans;
    }
};
```
# Have a Good Day 😊 UpVote?
['Array', 'Two Pointers', 'Greedy', 'Sorting', 'C++']