PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Molocoads

Simulate bubble elimination and maximize common prefix

Last updated: Mar 29, 2026

Quick Overview

This multi-task question evaluates simulation and array manipulation skills for the grid elimination task and scalable string-processing and prefix-search techniques for the longest common prefix task, testing competency in state updates, pattern detection, and efficient data-structure use.

  • medium
  • Molocoads
  • Coding & Algorithms
  • Machine Learning Engineer

Simulate bubble elimination and maximize common prefix

Company: Molocoads

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given **two independent coding tasks** (as in a multi-question OA). Solve each. ## Task A — Grid “bubble/candy” elimination simulation You are given an `m x n` grid `board` of integers. Repeatedly apply the following steps until the board becomes stable (no more eliminations): 1. **Mark for elimination**: Any cell that is part of a **horizontal or vertical** run of **3 or more equal values** is marked. - Marking is done based on the board state at the start of the round (i.e., all eliminations in a round happen simultaneously). 2. **Eliminate**: Set all marked cells to `0`. 3. **Gravity**: For each column independently, let all **non-zero** values “fall” toward the bottom, preserving their relative order, and fill the remaining cells at the top with `0` (equivalently: “zeros float up”). **Output:** Return the final stable grid. **Assumptions/constraints (typical OA):** - `1 <= m, n <= 50` (or similar) - Cell values are non-negative integers; `0` represents empty. --- ## Task B — Maximum longest common prefix length from two lists You are given two lists of strings: `A` and `B`. Choose **one** string `a` from `A` and **one** string `b` from `B`. Let `lcp(a, b)` be the length of the **longest common prefix** between `a` and `b`. **Output:** Return the **maximum** possible value of `lcp(a, b)` over all pairs `(a, b)`. **Constraints (to rule out brute force):** - `|A|` and `|B|` can be large (e.g., up to `1e5` total strings) - Total length of all strings can be large (e.g., up to `1e6`) - Lowercase English letters (or ASCII) for simplicity Your solution should be efficient enough that checking all pairs is too slow.

Quick Answer: This multi-task question evaluates simulation and array manipulation skills for the grid elimination task and scalable string-processing and prefix-search techniques for the longest common prefix task, testing competency in state updates, pattern detection, and efficient data-structure use.

Related Interview Questions

  • Support Dynamic Range Sums - Molocoads (hard)
  • Can you visit all rooms and score parentheses? - Molocoads (medium)
  • Find single element when others repeat k times - Molocoads (hard)
  • Compute subarray span for each element - Molocoads (hard)
Molocoads logo
Molocoads
Dec 27, 2025, 12:00 AM
Machine Learning Engineer
Take-home Project
Coding & Algorithms
3
0

You are given two independent coding tasks (as in a multi-question OA). Solve each.

Task A — Grid “bubble/candy” elimination simulation

You are given an m x n grid board of integers.

Repeatedly apply the following steps until the board becomes stable (no more eliminations):

  1. Mark for elimination : Any cell that is part of a horizontal or vertical run of 3 or more equal values is marked.
    • Marking is done based on the board state at the start of the round (i.e., all eliminations in a round happen simultaneously).
  2. Eliminate : Set all marked cells to 0 .
  3. Gravity : For each column independently, let all non-zero values “fall” toward the bottom, preserving their relative order, and fill the remaining cells at the top with 0 (equivalently: “zeros float up”).

Output: Return the final stable grid.

Assumptions/constraints (typical OA):

  • 1 <= m, n <= 50 (or similar)
  • Cell values are non-negative integers; 0 represents empty.

Task B — Maximum longest common prefix length from two lists

You are given two lists of strings: A and B.

Choose one string a from A and one string b from B. Let lcp(a, b) be the length of the longest common prefix between a and b.

Output: Return the maximum possible value of lcp(a, b) over all pairs (a, b).

Constraints (to rule out brute force):

  • |A| and |B| can be large (e.g., up to 1e5 total strings)
  • Total length of all strings can be large (e.g., up to 1e6 )
  • Lowercase English letters (or ASCII) for simplicity

Your solution should be efficient enough that checking all pairs is too slow.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Molocoads•More Machine Learning Engineer•Molocoads Machine Learning Engineer•Molocoads Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.