Swift💯
Greedy (accepted answer)\n\nimport Collections\n\nclass Solution {\n    func findMaximizedCapital(_ k: Int, _ w: Int, _ profits: [Int], _ capital: [Int]) -> Int
**Greedy (accepted answer)**\n```\nimport Collections\n\nclass Solution {\n    func findMaximizedCapital(_ k: Int, _ w: Int, _ profits: [Int], _ capital: [Int]) -> Int {\n        var indices = capital.indices.sorted {capital[$0] > capital[$1]}\n        var heap = Heap<Int>()\n\n        return (0 ..< k).reduce(into: w) { assets, _ in\n            while !indices.isEmpty, capital[indices.last!] <= assets {\n                heap.insert(profits[indices.popLast()!])\n            }\n            assets += heap.popMax() ?? 0\n        }\n    }\n}\n```
['Swift']