All practice tasks

Coding (Algo)

Shortest Shared Replay

Dynamic programming · Hard

Two devices have ordered action histories. A server wants the shortest replay containing both histories as subsequences, with deterministic text on ties.

Return the lexicographically smallest shortest common supersequence.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ a:string, b:string }

Input rules

  • Each lowercase ASCII character is an action kind.

What each field means

  • a and b — action sequences; each lowercase character is one action occurrence.

Output

Return value and rules

  • Return a shortest string that contains both inputs as subsequences.
  • Each input must retain its order, but may skip characters in the returned string.
  • Among equally short answers, choose the smallest in ASCII lexicographic order.

Constraints

  • 0 <= a.length, b.length <= 500
  • Repeated characters represent separate actions; they must not be deduplicated globally.

Examples

Example 1

{
  "a": "ab",
  "b": "ac"
}

Returns

"abc"

Example 2

{
  "a": "",
  "b": ""
}

Returns

""

Required complexity

O(nm) time and O(nm) space

What this task practices

Shortest Shared Replay is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as hard difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.