Python || Binary Search
Approach\nFirstly, sort nums in ascending order and build a prefix sum.\nThen do the Binary Search for each query of queries list to check, if prefix[i] <= q. \
# Approach\nFirstly, sort `nums` in ascending order and build a prefix sum.\nThen do the Binary Search for each query of `queries` list to check, if `prefix[i] <= q`. \n\n# Complexity\n- Time complexity: **O(N log N)**\n\n- Space complexity: **O(N)**\n\n# Code\n```python\nclass Solution:\n    def answerQueries(self, nums: list[int], queries: list[int]) -> list[int]:\n        nums.sort()\n        prefix = [nums[0]]\n        n = len(nums)\n\n        for i in range(1, n):\n            prefix.append(prefix[i - 1] + nums[i])\n\n        def search(q):\n            left, right = 0, n - 1\n\n            while left <= right:\n                mid = (left + right) >> 1\n\n                if prefix[mid] > q:\n                    right = mid - 1\n                else:\n                    left = mid + 1\n            \n            return left\n\n        return [search(q) for q in queries]\n```
['Binary Search', 'Prefix Sum', 'Python3']