PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Remove runs of length at least k

Last updated: Mar 29, 2026

Quick Overview

This question evaluates string manipulation, run-length detection, and algorithmic efficiency, focusing on tracking and removing maximal contiguous character groups. It is commonly asked in the Coding & Algorithms domain to assess practical application–level skills in designing linear-time, linear-space implementations that handle dynamic sequence collapses using appropriate data structures.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Remove runs of length at least k

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given a string s and an integer k (k >= 2), repeatedly remove every maximal contiguous group of the same character whose length is at least k, deleting the entire group (not just a chunk of size k). After each deletion, the remaining parts of the string collapse together and the process continues until no more deletions are possible. Return the final string. Examples: - s = 'abbbbc', k = 3 -> remove 'bbbb' -> 'ac'. - s = 'aaabbbcc', k = 3 -> remove 'aaa' and 'bbb' -> 'cc'. - s = 'baaabbbaac', k = 3 -> remove 'aaa' and 'bbb' -> 'bc' (no further deletions). Design an algorithm that runs in O(n) time and O(n) space using a stack-based approach (character + run length), and explain how you detect new removable runs formed after collapses.

Quick Answer: This question evaluates string manipulation, run-length detection, and algorithmic efficiency, focusing on tracking and removing maximal contiguous character groups. It is commonly asked in the Coding & Algorithms domain to assess practical application–level skills in designing linear-time, linear-space implementations that handle dynamic sequence collapses using appropriate data structures.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
Meta logo
Meta
Aug 12, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0

Given a string s and an integer k (k >= 2), repeatedly remove every maximal contiguous group of the same character whose length is at least k, deleting the entire group (not just a chunk of size k). After each deletion, the remaining parts of the string collapse together and the process continues until no more deletions are possible. Return the final string. Examples:

  • s = 'abbbbc', k = 3 -> remove 'bbbb' -> 'ac'.
  • s = 'aaabbbcc', k = 3 -> remove 'aaa' and 'bbb' -> 'cc'.
  • s = 'baaabbbaac', k = 3 -> remove 'aaa' and 'bbb' -> 'bc' (no further deletions). Design an algorithm that runs in O(n) time and O(n) space using a stack-based approach (character + run length), and explain how you detect new removable runs formed after collapses.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Software Engineer•Meta Software Engineer•Meta Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.