Beats 98.94%✅| Explicit VIDEO Explanation + Visualization + Simulation📙| Python, C++ 💻
Beats 98.94%\u2705| Explicit VIDEO Explanation + Visualization + Simulation\uD83D\uDCD9| Python, C++ \uD83D\uDCBB\n\n## 1. Proof\n Describe your first thoughts 
# Beats 98.94%\u2705| Explicit VIDEO Explanation + Visualization + Simulation\uD83D\uDCD9| Python, C++ \uD83D\uDCBB\n\n## 1. Proof\n<!-- Describe your first thoughts on how to solve this problem. -->\n### 1.1. Python3\n![image.png](https://assets.leetcode.com/users/images/c18fd50d-119c-4468-99b8-8cbcf810eb8c_1715005453.0016093.png)\n\n### 1.2. C++\n![image.png](https://assets.leetcode.com/users/images/270f23e7-a9e5-41a4-9a44-e8c34bb9cc89_1715005655.784192.png)\n\n## 2. Algorithms\n- Sorting\n- Two Pointers\n- Greedy\n## 3. Explanation\nLink of my explanation video: **`youtu.be/KRHzbHnw1rE`**\n(I can\'t attach it directly as Leetcode will hide my post, anyone knows how to fix this?)\n\n## 4. Code\n```python3 []\nclass Solution:\n    def numRescueBoats(self, people: List[int], limit: int) -> int:\n        res = 0 # Boats needed to use\n        people.sort() # Ascending\n        l, r = 0, len(people) - 1 # Left & Right pointers\n        while l <= r:\n            if people[l] + people[r] <= limit:\n                l += 1 # Try to carry "left" if possible\n            r -= 1 # Always carry "right"\n            res += 1 # +1 boat used\n        return res\n```\n```cpp []\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        int res = 0;\n        sort(people.begin(), people.end());\n        int l = 0, r = people.size() - 1;\n        while (l <= r) {\n            if (people[l] + people[r] <= limit) {\n                l++;\n            }\n            r--;\n            res++;\n        }\n        return res;\n    }\n};\n```\n## 5. Complexity (Explained in the video)\n- Time complexity: $$O(N*log(N) + N/2)$$ average, $$O(N*log(N) + N)$$ worst case\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n### Upvote if you find this solution helpful, thank you \uD83E\uDD0D
['Array', 'Two Pointers', 'Greedy', 'Sorting', 'C++', 'Python3']