Swift solution with binary search
\nclass Solution {\n    func answerQueries(_ nums: [Int], _ queries: [Int]) -> [Int] {\n        let queryCount = queries.count\n        var result = [Int](repea
```\nclass Solution {\n    func answerQueries(_ nums: [Int], _ queries: [Int]) -> [Int] {\n        let queryCount = queries.count\n        var result = [Int](repeating: 0, count: queryCount)\n        var nums = nums\n        let runningSum = nums.sorted().reduce(into: [Int]()) { $0.append(($0.last ?? 0) + $1)}\n        for (i, query) in queries.enumerated() {\n            result[i] = binarySearch(runningSum, query)\n        }\n        return result\n    }\n    \n    private func binarySearch(_ runningSum: [Int], _ query: Int) -> Int {\n        var left = 0\n        var right = runningSum.count - 1\n        while left <= right {\n            let mid = left + (right - left) / 2\n            if runningSum[mid] <= query {\n                left = mid + 1\n            } else {\n                right = mid - 1\n            }\n        }\n        return left\n    }\n}\n```
['Swift']