• + 3 comments

    Hi, My Swift soluition seems to be timing out. I unlocked the other swift solutions and noticed that solutions that have previously obtained 30 points are now timing out as well. Did the test cases change? Or is this because of the change in input format? Anyways the following is my solution, any recommendations appreciated.

    let testCases = Int(readLine()!)!
    var phoneBook = [String: String]()
    for i in 1...testCases {
        let nameAndNumber = readLine()!.characters.split(" ").map(String.init)    
        phoneBook[nameAndNumber[0]] = nameAndNumber[1]
    }
    
    while true {
        let name: String? = readLine(stripNewline: true)
        
        guard let n = name else {
            break
        }
        
        guard let phone = phoneBook[n] else {
            print("Not found")
            continue
        }
        
        print("\(n)=\(phone)")
            
    }