← Molocoads Interview Insights

Molocoads·Machine Learning Engineer·Online Assessment (OA)·Senior

SeniorPrefer not to say
Jun 2026

Summary

Two-question OA for a Machine Learning Engineer role at Molocoads. Both problems were algorithmic, nothing ML-specific, which was a bit of a surprise. The grid simulation one was the trickier of the two.

Questions Asked (2)

Q1

Given an m x n grid of integers, repeatedly eliminate any cells that are part of a horizontal or vertical run of 3 or more equal values (all in the same round, simultaneously), set them to zero, then apply gravity so non-zero values sink to the bottom of each column. Keep going until no more eliminations are possible. Return the final grid.

Algorithms & Data Structures
Author's notes

The simultaneous marking tripped me up at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a simulation loop: repeatedly scan the grid to mark all cells in horizontal or vertical runs of 3+ equal values, zero them simultaneously, then apply gravity column-wise. Continue until a full scan yields no eliminations, and return the final grid. Emphasize correctness of simultaneous marking and efficient gravity implementation.

Pro tip: Mention that marking must be done in a separate pass or with a boolean mask to avoid cascading eliminations within the same round, and that gravity can be implemented in O(m*n) per column using a write pointer to avoid repeated shifts.

1. Clarify rules and edge cases

Confirm that eliminations are simultaneous per round, runs must be exactly horizontal or vertical (not diagonal), and gravity applies after each round. Discuss edge cases like empty grid, single row/column, and all cells equal.

2. Design elimination detection

Scan each row and column to find runs of 3+ equal non-zero values. Use a boolean mask or set to mark cells for removal without modifying the grid during scanning.

3. Apply simultaneous removal and gravity

Set all marked cells to zero in one pass. Then for each column, compact non-zero values to the bottom using a write pointer from the bottom up, filling the top with zeros.

4. Iterate until stable

Repeat steps 2-3 until a full round produces no eliminations. Return the final grid.

5. Analyze complexity and optimize

Discuss time complexity: each round is O(m*n), and the number of rounds is bounded by the number of cells. Mention potential optimizations like tracking changed rows/columns or using union-find for large grids.

Key Points to Mention

  • Simultaneous elimination: mark all cells in runs before zeroing to prevent cascading within the same round.
  • Gravity implementation: use a write pointer per column to compact non-zero values in O(m) time per column.
  • Termination condition: loop until no cells are eliminated in a full scan.
  • Edge cases: empty grid, no eliminations, all cells eliminated, and grids with only one row or column.
  • Time complexity: O(k * m * n) where k is the number of rounds, worst-case O(m*n) rounds, but often much smaller.
  • Space complexity: O(m*n) for the grid and O(m*n) for the boolean mask, which can be optimized to O(m+n) if needed.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Given two large lists of strings A and B, find the maximum possible length of a longest common prefix between any pair (a, b) where a is from A and b is from B. The input is too large for a brute-force pairwise comparison.

Algorithms & Data Structures
Author's notes

Trie was the first thing that came to mind.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a trie (prefix tree) to store all strings from one list, then for each string in the other list, traverse the trie to find the longest common prefix. This reduces the time complexity from O(|A|*|B|*L) to O((|A|+|B|)*L), where L is the maximum string length.

Pro tip: Mention that you can optimize memory by storing only one list in the trie and streaming the other, and that early termination is possible if the maximum possible prefix length is found.

1. Clarify the problem

Confirm that the goal is to find the maximum length of the longest common prefix between any pair (a, b) with a in A and b in B, and that the lists are too large for pairwise comparison.

2. Choose a data structure

Select a trie (prefix tree) to efficiently store and query prefixes. Alternatively, consider sorting both lists and using binary search or two-pointer techniques.

3. Build the trie

Insert all strings from one list (e.g., A) into the trie. Each node represents a character, and paths from root represent prefixes.

4. Query for longest common prefix

For each string in the other list (B), traverse the trie as far as possible. The depth reached is the length of the longest common prefix with any string in A. Track the maximum depth.

5. Analyze complexity and optimize

Discuss time and space complexity: O((|A|+|B|)*L) time and O(|A|*L) space. Mention possible optimizations like early stopping if the maximum possible prefix length is found.

Key Points to Mention

  • Trie (prefix tree) data structure and its operations
  • Time complexity: O((|A|+|B|)*L) vs brute-force O(|A|*|B|*L)
  • Space complexity: O(|A|*L) for the trie
  • Alternative approaches: sorting and binary search, or using a hash set of prefixes
  • Handling edge cases: empty strings, no common prefix, one list empty
  • Scalability: streaming the second list to avoid loading both into memory

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.