>>109229497
func firstUniqueCharacterIndex(in word: String) -> Int? {
let frequency = word.reduce(into: [Character: Int]()) { $0[$1, default: 0] += 1 }
for (index, char) in word.enumerated() { if frequency[char] == 1 { return index }}
return nil
}
assert(firstUniqueCharacterIndex(in: "peepooj") == 6)
assert(firstUniqueCharacterIndex(in: "peepoo") == nil)
print("poopeepoopoo")
I've been asked a variant of this question before as well, couldn't believe they were giving me something that easy