Greedy | Sorting
Sort the nums array.\n\nThen try to take elements until you reach the query capacity.\n\nInstead of "taking" elements, I record the last j index you can reach.\
Sort the nums array.\n\nThen try to take elements until you reach the query capacity.\n\nInstead of "taking" elements, I record the last j index you can reach.\n\n```\nclass Solution:\n    def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums.sort()\n        n, m = len(nums), len(queries)\n        ans = [0] * m\n        \n        for i, query in enumerate(queries):\n            s = 0\n            k = -1\n            for j in range(n):\n                if s + nums[j] > query:\n                    break\n                \n                s += nums[j]\n                k = j\n            ans[i] = k + 1\n        \n        return ans\n```
['Python']