You are viewing a single comment's thread. Return to all comments →
swift solution
func whatFlavors(cost: [Int], money: Int) -> Void { // Write your code here var indexes:[Int: [Int]] = [:] for i in 0..<cost.count { if indexes[cost[i]] != nil { indexes[cost[i]]! += [i] } else { indexes[cost[i]] = [i] } } for i in 0..<cost.count - 1 { if cost[i] >= money { continue } if let value = indexes[money - cost[i]] { if value.count > 1 { print("\(value[0]+1) \(value[1]+1)") return } else if value.first! != i { print("\(i + 1) \(value.first! + 1)") return } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
swift solution