Count the Fewest Character Edits

Quick Overview

Find the minimum number of single-character insertions, deletions and replacements needed to transform one lowercase string into another.

Count the Fewest Character Edits

Company: Infosys

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return the fewest single-character edits needed to change the string `before` into the string `after`. One edit may insert a character, delete a character, or replace one character with another. Each such edit counts as one operation. ### Examples **Example 1** ```text Input: before = "plane", after = "plans" Output: 1 ``` Replacing the final `e` with `s` completes the change in one edit. **Example 2** ```text Input: before = "", after = "moss" Output: 4 ``` Starting from an empty string requires inserting its four characters. ### Constraints - `0 <= before.length <= 500` - `0 <= after.length <= 500` - Both strings contain lowercase English letters only.

Overview: Find the minimum number of single-character insertions, deletions and replacements needed to transform one lowercase string into another.

Infosys logo
Infosys
Oct 14, 2026
mediumSoftware EngineerOtherCoding & Algorithms
4
0

Problem

Return the fewest single-character edits needed to change the string before into the string after.

One edit may insert a character, delete a character, or replace one character with another. Each such edit counts as one operation.

Examples

Example 1

Input: before = "plane", after = "plans"
Output: 1

Replacing the final e with s completes the change in one edit.

Example 2

Input: before = "", after = "moss"
Output: 4

Starting from an empty string requires inserting its four characters.

Constraints

  • 0 <= before.length <= 500
  • 0 <= after.length <= 500
  • Both strings contain lowercase English letters only.