MEDIUMasked at 1 company

Extra Characters in a String

A medium-tier problem at 57% community acceptance, tagged with Array, Hash Table, String. Reported in interviews at PornHub and 0 others.

Founder's read

Extra Characters in a String sits at the intersection of string parsing and dynamic programming. You're given a string and a dictionary, and need to find the minimum number of extra characters left over after breaking the string into valid dictionary words. It's medium difficulty with a solid 57% acceptance rate, which means half the candidates don't nail the approach on first try. The pattern is deceptive: greedy doesn't work, and a naive recursive solution will time out. This is exactly the kind of problem where you either see the DP structure immediately or you're rewriting your solution under time pressure.

Companies asking
1
Difficulty
MEDIUM
Acceptance
57%

Companies that ask "Extra Characters in a String"

If this hits your live OA

Extra Characters in a String is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

The trap is thinking you can greedily match words from left to right. You can't. You need to frame this as a DP problem where each position in the string represents a state: what's the minimum number of extra characters from here to the end. For each position, you try matching all possible dictionary words starting there, and for each valid match, you recurse. A Trie can optimize the dictionary lookup to avoid O(n*m) string comparisons. The real skill is recognizing that this is a bottom-up optimization problem, not a greedy parsing problem. If you blank on the transition during your assessment, StealthCoder reads the problem and delivers a working DP solution in seconds, invisible to the proctor, so you can move forward without panic.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Extra Characters in a String recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Extra Characters in a String interview FAQ

Is this problem actually hard, or does it just look hard?+

It's a misdirect. The problem looks like string matching, but it's really DP. Once you recognize the pattern (min extra characters from position i onward), the code is straightforward. The acceptance rate of 57% reflects that recognition gap, not implementation difficulty.

Does greedy work if I always match the longest word first?+

No. A greedy approach fails because matching the longest word early can leave you with unmatchable garbage later. You need to explore all possible matches at each position and choose the path that minimizes total extras. That's DP.

When would a Trie actually matter here?+

If the dictionary is large and the string is long, checking 'is this substring in the dictionary' becomes expensive. A Trie lets you check all words starting at position i in O(word length) time instead of O(dictionary size). It's an optimization, not a requirement.

What's the common pitfall candidates hit?+

Writing a recursive solution without memoization and watching it time out. Or recognizing DP is needed but implementing the recurrence wrong. The state definition has to be crystal clear: dp[i] = min extras from index i to end, assuming everything before i is matched.

Has PornHub actually asked this, or is that data noise?+

It's in the reported dataset once. That doesn't mean it's a common pattern at that company. Treat this as a legitimate medium DP problem on the interview circuit, not a company-specific signal.

Want the actual problem statement? View "Extra Characters in a String" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.