Java solution to carry at most K people
\npublic int numRescueBoats(int[] people, int limit, int k) {\n        Arrays.sort(people);\n        int ans = 0;\n        int l = 0;\n        int r = people.le
```\npublic int numRescueBoats(int[] people, int limit, int k) {\n        Arrays.sort(people);\n        int ans = 0;\n        int l = 0;\n        int r = people.length - 1;\n\n        while (l <= r) {\n            int sum = 0;\n            int count = 0;\n            while (r > l && count < k && sum + people[r] <= limit) {\n                sum += people[r--];\n                count++;\n            }\n            while (l <= r && count < k && sum + people[l] <= limit) {\n                sum += people[l++];\n                count++;\n            }\n            ans++;\n        }\n        return ans;\n    }\n```
[]