How to remove consecutive character from a string which exactly matches k as: "aaabaaa","aaab","abcd" or "aaaba" or "aaabaa
Here is my code: class RemoveCharacters { func removeKOccurrences(_ data: String, _ k: Int) -> String { let text = Array(data) // Get the length let n: Int = text.count if (n == 0 || k <= 0) { return " " } var result: String = "" // Use to count character frequency var count: [Int] = Array(repeating: 0, count: 256) var i: Int = 0 while (i < n { count[Int(UnicodeScalar(String(text[i]))!.value)] += 1 i += 1 } i = 0 while (i < n) { if (count[Int(UnicodeScalar(String(text[i]))!.value)] != k) { // Include the resultant character result = result + String(text[i]) } i += 1 } return result } } let task: RemoveCharacters = RemoveCharacters() var d = task.removeKOccurrences("aaabaaa", 1) print(d) //HERE IS THE TEST CASES: Test Cases: "aaabbbc", 3 => "c" "abbbcddfg", 1 => "bbbdd" "abcd", 2 => "abcd" "abcd", 1 => " " "aaabaaa", 3 => "b" "aaaab", 3 => "aaaab" "bbbaabb", 3 => aabb We need to verify all the cases but out of it 5th and 7th i am unable to verify so help me...m fresher in swift.