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.
You are given two independent coding tasks (as in a multi-question OA). Solve each.
You are given an m x n grid board of integers.
Repeatedly apply the following steps until the board becomes stable (no more eliminations):
0
.
0
(equivalently: “zeros float up”).
Output: Return the final stable grid.
Assumptions/constraints (typical OA):
1 <= m, n <= 50
(or similar)
0
represents empty.
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)
1e6
)
Your solution should be efficient enough that checking all pairs is too slow.