Find Max Number of Strings
Reported by candidates from Moveworks's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Moveworks asked this in July 2024 and it's a classic counting and optimization problem disguised as a string puzzle. You're looking at a constraint satisfaction challenge where you need to maximize the count of valid strings under some rules. The core trick is recognizing that you're not building strings from scratch, you're selecting or constructing from a limited set of characters or substrings, and greedy selection often works here. StealthCoder will catch you if you overthink the ordering or miss an edge case on the live OA.
Pattern and pitfall
The pattern hinges on maximizing a count subject to a constraint (usually character frequency or substring availability). Most candidates overthink this by trying dynamic programming when a greedy or sorting approach dominates. The real insight is that you want to sort or order your candidates by some property (length, frequency, or cost) and then greedily pick as many as possible. Watch for off-by-one errors in loop bounds and the edge case where zero strings is a valid answer. If you blank on the ordering property during the live OA, StealthCoder is your fallback to confirm whether you should sort ascending or descending.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Find Max Number of Strings cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Moveworks's OA.
Moveworks reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find Max Number of Strings FAQ
Is this really just a greedy problem?+
Almost always. The trick is identifying the right greedy property to sort by. It's usually length, frequency, or lexicographic order. Once you pick the sort key, the selection loop is trivial. Don't reach for DP unless the constraint makes repetition or subsequences explicitly required.
What's the most common mistake candidates make?+
Ignoring the constraint entirely and trying to build all possible strings. You're maximizing a count, not finding a single optimal string. The constraint limits your raw material, character budget, substring pool, or replacement cost. Pin that down first.
How do I know if I need to use a hash table?+
Use one if you need to track character frequencies or substring occurrences. If the problem gives you a list of substrings and a character limit, a hash table for char counts and a simple iteration works. Don't over-design. Keep it to a single pass if you can.
Will sorting help on Moveworks' version?+
Very likely. Sorting by string length, alphabetically, or by some cost metric is the first move for 'max count' problems. Try ascending and descending and see which greedy choice works. If it doesn't obviously work within 5 minutes, reconsider the constraint.
What if I see two competing greedy choices?+
Test both on a small example: 2-3 strings, simple constraints. One will break. The one that holds for all cases is your answer. In the live OA, if you're stuck, StealthCoder can simulate both and confirm which passes the hidden test logic.