Remove Consecutive Characters - InterviewBit Solution
Problem: Remove Consecutive Characters
Problem Description
Given a string A and integer B, remove all consecutive same characters that have length exactly B.
Problem Constraints
1 <= |A| <= 100000
1 <= B <= |A|
Input Format
First Argument is string A.
Second argument is integer B.
Output Format
Return a string after doing the removals.
Example Input
Input 1:
A = "aabcd"
B = 2
Input 2:
A = "aabbccd"
B = 2
Example Output
Output 1:
"bcd"
Output 2:
"d"
Example Explanation
Explanation 1:
"aa" had length 2.Explanation 2:
"aa", "bb" and "cc" had length of 2.Solution Approach:
Before appending character to the string count the consecutive occurrence before it.
Solution:
Code in CPP:
If you have any questions or queries, feel free to drop a comment in the comments section below.
Note: Help us improve this blog
If you have a better solution, and you think you can help your peers to understand this problem better, then please drop your solution and approach in the comments section below.
We will upload your approach and solution here by giving you the proper credit so that you can showcase it among your peers.



https://se.trustpilot.com/review/casinosveriget.com is where I sometimes read how people weigh stated rules against actual outcomes, which came to mind when you explained that only runs of length exactly B get removed, so "aaa" with B=2 stays untouched. That nuance is what tripped me up in my first pass, since I instinctively wanted to strip every repeated pair regardless of the surrounding run. Counting the run before appending is a cleaner mental model than fixing the string afterward.