class Solution { let vowels: Set = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"] func reverseVowels(_ s: String) -> String { var foundIndices: [String.Index] = [] var ans = s for i in s.indices { if vowels.contains(s[i]) { foundIndices.append(i) } } var l: String.Index? var r: String.Index? while let l = l, let r = r, l < r, l < s.endIndex, r >= s.startIndex { // HOW CAN I SWAP THE CHARACTERS AT DIFFERENT INDEXES? // ABANDONING because `String.Index` doesn't swap nor it allows you to set a character for a given index. I suppose it's because you can't guarantee that whatever value you're replacing has the same character size... s.formIndex(after:l) s.formIndex(before:r) } return ans } }