Try ones more using my hints || 2 approach DP and two pointer
Approach 1 (DP, Brute force)\n- Note - this approach will give Time limit exceet because the time complexity is O(n^2).\n- Sort the people array in decreasing o
# Approach 1 (DP, Brute force)\n- Note - this approach will give Time limit exceet because the time complexity is O(n^2).\n- Sort the people array in decreasing order.\n- take a new array boats of length equal to people array because at most n boats are needed to pickup n people and fill each index with limit to define max capacity\n- Add most waited person in 1st boat \n- For each remaning person in decreasing order of their weight find the best fit boat in which he can fit and should not exceed more then 2 persons.\n- See the code to understand the approach.\n\n# Complexity\n- Time complexity: O(n^2)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\n    public int numRescueBoats(int[] people, int limit) {\n        int count = 0;\n        if(people == null || people.length == 0) return count;\n        Arrays.sort(people);\n        int boats[] = new int[people.length];\n        Arrays.fill(boats, limit);\n        boats[0] -= people[people.length-1];\n        for(int i = people.length-2; i>=0; i--){\n            for(int j = 0; j<people.length-i; j++){\n                if(boats[j] >= people[i]){\n                    if(boats[j] == limit) boats[j] -= people[i];\n                    else boats[j] = 0;\n                    break;\n                }\n            }\n        }\n        for(int i = 0; i<people.length; i++){\n            if(boats[i] < limit) count++;\n        }\n        return count;\n    }\n}\n```\n\n\n# Approach 2 (Two pointer, efficent)\n- Sort the people array in decreasing order.\n- Take 2 pointers high and low pointing to both ends of array\n- Each time while low <= high :-\n    - Check if sum of both low and high person weigth is less then or equals to limit, if this is true high = high -1, low  = low + 1 boatCount++ , because these 2 people can taken in 1 boat \n    - else only person with high weigth can be taken in current baot so do high-- and count++.\n\n# Complexity\n- Time complexity: O(n log(n))\n\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\n    public int numRescueBoats(int[] people, int limit) {\n        int count = 0;\n        if(people == null || people.length == 0) return count;\n        Arrays.sort(people);\n        int l = 0, h = people.length-1;\n        while(l <= h){\n            if(people[l]+people[h] > limit) {\n                h--;\n            } else {\n                h--;\n                l++;\n            }\n            count++;\n        }\n        return count;\n    }\n}\n```
['Array', 'Two Pointers', 'Greedy', 'Sorting', 'Java']