[Python] (prefix sum + binary search) with explanation Time = O (n log n + m log n)
Sort the array, compute the prefix sum, search each query in the prefix sum array and append it to res.\n\n\nclass Solution:\n    def answerQueries(self, nums: 
Sort the array, compute the prefix sum, search each query in the prefix sum array and append it to res.\n\n```\nclass Solution:\n    def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n        nums.sort()\n        preSum = [0]\n        for n in nums:\n            preSum.append(preSum[-1]+n)\n        res = []\n        for q in queries:\n            indx = bisect_right(preSum,q)\n            res.append(indx-1)\n        return res\n```\n\n**Upvote** if you like this post.\n\n**Connect with me on [LinkedIn](https://www.linkedin.com/in/meida-chen-938a265b/)** if you\'d like to discuss other related topics\n\n\uD83C\uDF1F If you are interested in **Machine Learning** || **Deep Learning** || **Computer Vision** || **Computer Graphics** related projects and topics, check out my **[YouTube Channel](https://www.youtube.com/@meidachen8489)**! Subscribe for regular updates and be part of our growing community.
[]