MEDIUMasked at 1 company

Count Ways To Build Good Strings

A medium-tier problem at 59% community acceptance, tagged with Dynamic Programming. Reported in interviews at Citadel and 0 others.

Founder's read

Count Ways to Build Good Strings is a medium-difficulty dynamic programming problem that shows up in assessments at places like Citadel. You're given constraints on string length and character counts, and you need to figure out how many valid strings you can construct. It's the kind of problem where the brute force approach (generate all strings, filter, count) times out instantly, but the DP solution clicks once you see the pattern. About 59% of candidates pass it, which means a solid chunk blank or implement the wrong recurrence. This is exactly the type of problem where StealthCoder surfaces a working solution in seconds if you hit it cold during your live assessment.

Companies asking
1
Difficulty
MEDIUM
Acceptance
59%

Companies that ask "Count Ways To Build Good Strings"

If this hits your live OA

Count Ways To Build Good Strings 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. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.

Get StealthCoder
What this means

The trick is recognizing this as a counting problem where you build strings incrementally and track remaining characters as state. You use dynamic programming with memoization or a bottom-up table, where your state is something like 'how many ways can I build a string of length L given I have X low characters and Y high characters left'. The pitfall is trying to enumerate strings directly or overthinking the state space. Most candidates either miss that you're supposed to think recursively about adding characters one at a time, or they set up the DP but get the transitions wrong. The recurrence usually involves deciding whether to add a low or high character and multiplying out the valid continuations. Since only Citadel reports asking it, it's not saturated in mock prep pools, so you might not drill it. That's where the safety net matters: if this lands in your online assessment and you blank on the DP structure, StealthCoder runs invisibly and hands you the code.

Pattern tags

The honest play

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

Count Ways To Build Good Strings 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. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Ways To Build Good Strings interview FAQ

How hard is this compared to standard coin change or knapsack DP?+

It's in the same family. The state-space reasoning is similar, but the constraint translation is trickier. You're not optimizing a sum, you're counting valid combinations under length and character bounds. Medium difficulty is fair. The 59% pass rate suggests it's easier than some DP problems but still trips up candidates who skip the recurrence on paper first.

What's the most common mistake?+

Trying to iterate character by character without nailing down the state. Candidates often start coding a recursive function but don't define memoization keys correctly, so they either recompute the same subproblems or overcount. Write out the state definition and transitions on paper before coding.

Is this asked frequently outside Citadel?+

It appears rarely in public reports. Only Citadel is on record asking it, so it's not a common interview rotation. That makes it a low-probability but high-impact problem if it lands in your OA. Most prep focuses on more common DP patterns.

Can I solve this without bottom-up DP?+

Yes. Top-down with memoization (recursion plus cache) is cleaner for most people and easier to debug. Define a recursive function that returns the count for a given length and remaining character budget, cache results, and return. Both approaches have the same complexity, so pick the one you're faster with.

How does this relate to combinatorics problems I see in interviews?+

It's combinatorics underneath, but the DP angle is the expected approach. You're not using nCr or factorials directly. The constraint interpretation (length limits, character caps) is what makes it feel like a DP problem instead of a math problem. That transition is what candidates often miss.

Want the actual problem statement? View "Count Ways To Build Good Strings" 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.