All practice tasks

Coding (Algo)

Minimum Text Edits

Dynamic programming · Medium

A text comparison tool reports how many single-character changes transform one short identifier into another. Its edit model is deliberately small: insert, delete or replace one character. It does not model word moves or spelling semantics.

Return the minimum number of allowed edits needed to turn a into b. Each edit costs one.

Input

Call

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

Input shape

A JSON object { "a": string, "b": string }.

Fields

  • a and b are printable ASCII strings. Matching is case-sensitive and spaces are ordinary characters.

Output

Return value

  • Return one integer minimum cost. Equal strings return 0.
  • Insertion adds one character, deletion removes one and replacement changes one.
  • Swapping two adjacent characters is not a single operation.
  • Transforming an empty string costs the length of the other string.

Constraints

  • 0 <= a.length, b.length <= 2000.
  • Characters have ASCII codes 32..126. Unicode normalization is outside this contract.
  • Return only the cost; reconstructing the edit sequence is not required.

Examples

Example 1

{
  "a": "kitten",
  "b": "sitting"
}

Returns

3

Replace k with s, replace e with i and insert g.

Example 2

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

Returns

2

A transposition is not one allowed edit.

Required complexity

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

What this task practices

Minimum Text Edits 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.