Advertisement
greedydev

Untitled

Nov 15th, 2022
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.56 KB | None | 0 0
  1. func testPhoneNumbers(_ numbers: [String]) -> Bool {
  2.     var tmp = numbers
  3.     while !tmp.isEmpty {
  4.         let numberToTest = tmp.removeFirst()
  5.         if !tmp.allSatisfy({ !$0.hasPrefix(numberToTest) }) {
  6.             return false
  7.         }
  8.     }
  9.     return true
  10. }
  11.  
  12. let testCount = Int(readLine()!)!
  13.  
  14. for _ in 1...testCount {
  15.     let phoneNumberCount = Int(readLine()!)!
  16.     var phoneNumbers = [String]()
  17.     for _ in 1...phoneNumberCount {
  18.         phoneNumbers.append(readLine()!)
  19.     }
  20.     phoneNumbers.sort()
  21.     print(testPhoneNumbers(phoneNumbers) ? "YES" : "NO")
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement