top of page

### Looking to master object-oriented and system design for tech interviews or career growth?

• Improve your system design and machine coding skills.

• Study with our helpful resources.

**We're in beta mode and would love to hear your feedback.

Search

# Remove Consecutive Characters - InterviewBit Solution

### 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.

Input 1:

A = "aabcd"

B = 2

Input 2:

A = "aabbccd"

B = 2

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.