Java C++ solution
C++  ===================================\n\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        int i = 0, count = 0, j
C++  ===================================\n```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) {\n        int i = 0, count = 0, j = people.size() - 1;\n        sort(people.begin(), people.end());\n        while (i <= j) {\n            if (people[i] + people[j] > limit) {\n                j--;\n            } else {\n                i++;\n                j--;\n            }\n            count++;\n        }\n        return count;\n    }\n};\n```\n\nJava ===================================\n```\nclass Solution {\n    public int numRescueBoats(int[] arr, int limit) {\n        Arrays.sort(arr);\n        int i = 0, j = arr.length - 1, count = 0;\n        while (i <= j) {\n            if (arr[i] + arr[j] > limit) {\n                j--;\n            } else {\n                j--;\n                i++;\n            }\n            count++;\n        }\n        return count;\n    }\n}\n```
[]