Shortest Way to Form String
A medium-tier problem at 61% community acceptance, tagged with Two Pointers, String, Binary Search. Reported in interviews at Pinterest and 0 others.
Shortest Way to Form String is a medium-difficulty string problem that Pinterest has asked in their technical interviews. You get a target string and a source string, and you need to figure out the minimum number of passes through source to form the target by taking characters in order. The 61% acceptance rate means most candidates who see this problem don't nail it on first try. The trick isn't obvious if you haven't internalized the greedy pattern, which is exactly where StealthCoder steps in. If this problem hits your live assessment and the approach doesn't click, you get an invisible working solution in seconds without the proctor catching on.
Companies that ask "Shortest Way to Form String"
Shortest Way to Form 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 StealthCoderThe core insight is greedy: for each character in target, scan through source from left to right and grab the first matching character. When you hit the end of source without finding a match, either source can't form target at all or you move to the next pass and reset your source pointer. Most candidates either brute-force with substring searches (too slow) or overthink with dynamic programming. The fast path uses two pointers: one for target, one for the current position in source. Binary search enters the picture as an optimization if you precompute character positions in source, letting you find the next occurrence in log time instead of linear. The greedy approach works because taking the earliest match never locks you out of a later solution. When you're stuck in the OA and haven't seen this pattern, StealthCoder surfaces the pointer-based solution and the binary search variant instantly.
Pattern tags
You know the problem.
Make sure you actually pass it.
Shortest Way to Form 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.
Shortest Way to Form String interview FAQ
What's the actual trick to this problem?+
Greedy: always take the first character match you find in source. When source runs out, start a new pass. This minimizes passes because taking early characters never blocks a valid solution. Most candidates miss this and try DP or substring matching, which either times out or over-complicates.
Do I need binary search to pass?+
No. Two pointers with linear scan through source works and passes test cases. Binary search is an optimization if you precompute character positions in source. Pinterest likely accepts both. Binary search matters if the strings are huge and you're optimizing beyond 'correct and fast enough'.
What if a character in target doesn't exist in source?+
Return -1. The problem is impossible. Check this early. Most implementations handle it by tracking whether you made progress in a pass through source. If a pass completes with no matches for a target character, you're done.
Is this still asked at other companies?+
The input shows Pinterest as the only reported company. That doesn't mean it's exclusive to them, but it's not a tier-1 FAANG classic. It's a solid medium that tests greedy reasoning and string manipulation, so expect it from mid-tier tech companies or those emphasizing algorithmic elegance.
How does this relate to two pointers and greedy?+
Two pointers let you walk through source and target simultaneously without backtracking. Greedy is the decision rule: always pick the earliest match. Together they create the linear-time solution. Binary search builds on this by replacing the linear scan with a log lookup for the next character position.
Want the actual problem statement? View "Shortest Way to Form String" on LeetCode →