Java Easy Solution with Explanation || Two Pointers and Sorting
Intuition\n Describe your first thoughts on how to solve this problem. \nTwo Pointers and Sorting.\n\n# Approach\n Describe your approach to solving the problem
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTwo Pointers and Sorting.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSorting the People array.\nUsing Two Pointer checking for the sum of people a boat can carry.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N + NlogN)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n![leetcodeupvotetrick.png](https://assets.leetcode.com/users/images/bae988c6-a099-4183-89de-3b500df4c66f_1680524554.0548103.png)\n\n\n# Code\n```\nclass Solution {\n    public int numRescueBoats(int[] arr, int n) {\n        int res = 0,bl;\n        Arrays.sort(arr);\n        int l=0,r=arr.length-1;\n        while(l<=r){\n            if(arr[l]+arr[r]<=n){\n                l++;\n                r--;\n                res++;\n            }\n            else{\n                r--;\n                res++;\n            }\n        }\n        return res;\n    }\n}\n\n```
['Java']