Given a string S. Count the characters that have ‘N’ number of occurrences. If a character appears consecutively it is counted as 1 occurrence.
Input: S = "abc", N = 1 Output: 3 Explanation: 'a', 'b' and 'c' all have 1 occurrence.
Input: S = "geeksforgeeks", N = 2 Output: 4 Explanation: 'g', 'e', 'k' and 's' have 2 occurrences.
You don't need to read input or print anything. Your task is to complete the function getCount() which takes the string S and an integer N as inputs and returns the count of the characters that have exactly N occurrences in the string. Note that the consecutive occurrences of a character have to be counted as 1.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes