Remove Consecutive Characters | InterviewBit | Solution

Note: If you want a detailed explanation, here you go: Remove Consecutive Characters | InterviewBit | Solution Explained.

class Solution:
    def solve(self, s, k):
        a = ["."]

        for c in s:
            if a[-1][0] == c:
                a[-1] += c
            else:
                a.append(str(c))
        
        a = a[1:]
        ns = ""
        for temp in a:
            final_len = len(temp)%k
            ns += temp[0]*final_len
        
        return ns
Avatar for Tanishq Chaudhary

Producing high-quality intuitive explanations of interview problems. Currently covering LeetCode and InterviewBit.

    Comments

    1. Please write the proof.

    2. This solution need an amendment for 2 digit number.

    3. Please write a Proof for this

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.