All practice tasks

Coding (Algo)

Measure the Shared Ordered Sequence

Dynamic programming · Medium

A comparison tool summarizes two short event-code strings by the longest sequence of codes they share in the same relative order. Unmatched codes may be skipped. The shared sequence does not need to be contiguous in either input.

Return the length of the longest common subsequence while preserving relative order in both strings.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ a: string, b: string }

Fields

  • a and b are case-sensitive printable ASCII strings. Spaces are ordinary characters.

Output

Return value

  • Return an integer length, not a substring or the sequence itself.
  • Characters may be skipped but never reordered. An empty operand gives zero.

Constraints

  • 0 <= a.length, b.length <= 1000.

Examples

Example 1

{
  "a": "abcde",
  "b": "ace"
}

Returns

3

Example 2

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

Returns

1

Required complexity

O(nm) time and O(min(n,m) + 1) auxiliary space

What this task practices

Measure the Shared Ordered Sequence 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 medium 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.