import Foundation
func solution(_ str1:String, _ str2:String) -> Int {
let alphabet = "abcdefghijklmnopqrstuvwxyz"
let lowerStr1 = str1.lowercased().map { $0 }
let lowerStr2 = str2.lowercased().map { $0 }
var set1 = [String]()
var set2 = [String]()
var union = [String]()
var intersection = [String]()
for i in 0..<lowerStr1.count-1 {
let ch1 = lowerStr1[i]
let ch2 = lowerStr1[i+1]
if alphabet.contains(ch1), alphabet.contains(ch2) {
set1.append("\(ch1)\(ch2)")
}
}
for i in 0..<lowerStr2.count-1 {
let ch1 = lowerStr2[i]
let ch2 = lowerStr2[i+1]
if alphabet.contains(ch1), alphabet.contains(ch2) {
let str = "\(ch1)\(ch2)"
set2.append(str)
if set1.contains(str) {
intersection.append(str)
set1.remove(at: set1.firstIndex(of: str)!)
set2.remove(at: set2.firstIndex(of: str)!)
}
}
}
union = set1 + set2 + intersection
return intersection.isEmpty && union.isEmpty ? 65536 :Int(Double(intersection.count)/Double(union.count)*65536)
}