Two pointers but without sorting, fast than 97%
Very similar to the common solution that uses two pointers (after sorting the array) and the greedy idea (I do not give proof here but you may be able to intuit
Very similar to the common solution that uses two pointers (after sorting the array) and the greedy idea (I do not give proof here but you may be able to intuitively figure it out). But what I think of is, the two pointers are not the head/tail index of the array, but the left/right boundary of the range [1,limit].\nSo it is kind of bucket sort. Find the largest / smallest element sequentially by iterating the possible values.\n```\nclass Solution {\npublic:\n    int numRescueBoats(vector<int>& people, int limit) \n    {\n        vector<int>p(limit+1,0);\n        for (int w: people)\n            p[w]++;\n        \n        int count = 0;\n        int x = limit;\n        int y = 1;\n        \n        while (x>0)\n        {\n            while (x>0 && p[x]==0)\n                x--;\n            if (x==0) break;\n            count++;\n            p[x]--;\n            \n            while (y+x<=limit && p[y]==0) \n                y++;\n            if (y+x<=limit && p[y]>0) \n                p[y]--;\n        }\n                \n        return count;\n    }\n};\n```\nObviously the time complexity is o(n+limit).
[]