InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

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:


Output 2:


Example Explanation

Explanation 1:

 "aa" had length 2.

Explanation 2:

 "aa", "bb" and "cc" had length of 2.

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Remove Consecutive Characters on Interview Code Editor
  • Hint 1
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions