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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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]...