💯JAVA Solution Explained in HINDI
https://youtu.be/RHf0P-t4cjY\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote 
https://youtu.be/RHf0P-t4cjY\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\nSubscribe Goal:- 400\nCurrent Subscriber:- 352\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int numRescueBoats(int[] people, int limit) {\n        \n        int boatCount = 0;\n        // Arrays.sort(people);\n\n        int[] count = new int[limit + 1];\n        for (int p : people) {\n            count[p]++;\n        }\n\n        int idx = 0;\n        for (int val = 1; val <= limit; val++) {\n            while (count[val]-- > 0) {\n                people[idx++] = val;\n            }\n        }\n\n        int left = 0;\n        int right = people.length - 1;\n\n        while(left <= right) {\n            int sum = people[left] + people[right];\n\n            if(sum <= limit) {\n                boatCount++;\n                left++;\n                right--;\n            }\n            else {\n                boatCount++;\n                right--;\n            }\n        }\n        return boatCount;\n    }\n}\n```\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n```\nclass Solution {\n    public int numRescueBoats(int[] people, int limit) {\n        \n        int boatCount = 0;\n        Arrays.sort(people);\n\n        int left = 0;\n        int right = people.length - 1;\n\n        while(left <= right) {\n            int sum = people[left] + people[right];\n\n            if(sum <= limit) {\n                boatCount++;\n                left++;\n                right--;\n            }\n            else {\n                boatCount++;\n                right--;\n            }\n        }\n        return boatCount;\n    }\n}\n```\n
['Java']