Question 5: Replace consecutive occurrences of the character from given input string.
You are given a string S. If a character 'c' occurs consecutively N times in the string. Replace these consecutive occurrences of the character 'c' with (N,c) in the string.
Eg:
Input: "1222311"
Output: "(1, 1) (3, 2) (1, 3) (2, 1)"
Here, character 1 occurs only once. It is replaced by (1,1). Then the character 2 occurs 3 times, and it is replaced by (3,2) and so on.
You are given a string S. If a character 'c' occurs consecutively N times in the string. Replace these consecutive occurrences of the character 'c' with (N,c) in the string.
Eg:
Input: "1222311"
Output: "(1, 1) (3, 2) (1, 3) (2, 1)"
Here, character 1 occurs only once. It is replaced by (1,1). Then the character 2 occurs 3 times, and it is replaced by (3,2) and so on.