Cheapest Character Deletions to Make Two Display Names Match

Last updated: November 29, 2026

Quick Overview

Given two display names, you may delete characters from either one, paying each deleted character's code point value. Return the minimum total cost to make the two strings identical.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given two display names, you may delete characters from either one, paying each deleted character's code point value. Return the minimum total cost to make the two strings identical.

A Meta technical screen twist on edit distance, framed around reconciling display names across Facebook and Instagram accounts. The interviewer checks whether you adapt the LCS style table to weighted costs rather than reaching for unit-cost edit distance.

What the Interviewer Expects
  • Define cost[i][j] for prefixes of both names
  • Handle base rows as cumulative deletion costs
  • Match equal characters for free
  • Otherwise delete the cheaper of the two tails
  • Reduce to O(min(n, m)) memory
Key Topics to Cover
2D dynamic programming
Weighted edit distance
Common subsequence
Rolling array
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How does this relate to the maximum-weight common subsequence?
  • What if insertions are also allowed with their own cost?
  • How would you report which characters were deleted?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Inputs are two strings a and b, length up to 1000 each. Deleting character ch costs ord(ch). Only deletions are allowed. Return the smallest total cost after which a == b....

High-Level Design

Let cost[i][j] be the minimum cost to make a[:i] and b[:j] equal. If one prefix is empty, you must delete all of the other, so the base row and column are running sums of code points. If `a[i-1]...


Submit Your Answer
Markdown supported