PIXELBANKv9.1.0
Menu

Edit Distance for OCR Correction

Problem Statement

In Optical Character Recognition (OCR), text extracted from images often contains errors. Edit Distance (Levenshtein Distance) measures how different two strings are, which helps in:

  • Spell checking OCR output
  • Finding the closest dictionary word
  • Post-processing recognized text

Given two strings source and target, find the minimum number of operations required to convert source to target. The allowed operations are:

  1. Insert a character
  2. Delete a character
  3. Replace a character

Constraints

  • 0≤len(source),len(target)≤5000 \leq len(source), len(target) \leq 500
  • Strings contain lowercase English letters only

Example:

Input:
source = "kitten", target = "sitting"
Output:
3
Reasoning:

kitten → sitten (replace k with s) → sittin (replace e with i) → sitting (insert g)

🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Edit Distance for OCR Correction - Medium | PixelBank