Count Substring
Reported by candidates from YahoO's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Yahoo's Count Substring question landed on candidates in March 2025, and it's a sliding-window pattern masquerading as a substring problem. You're likely counting occurrences of a pattern or finding substrings that meet a specific condition. The trick isn't the counting itself. It's recognizing that you don't need to check every substring independently. A two-pointer or window approach collapses the work from brute force O(n squared) down to linear. StealthCoder can feed you the window template if the pattern slips your mind under pressure.
Pattern and pitfall
The sliding-window pattern here means you expand and contract a window across the string, only counting or tracking valid substrings as the boundaries shift. Common pitfall: candidates write nested loops to count substrings, which times out. The insight is that if you know how many valid substrings end at position i, you don't recalculate from scratch at position i+1. You adjust. The window moves, characters enter and leave, and you update your count incrementally. Yahoo tends to test this as a constraint satisfaction problem: count substrings where some property holds (character frequency, distinctness, sum within range). StealthCoder lets you verify your window logic is correct before submission if you're unsure.
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 Count Substring 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 YahoO's OA.
YahoO 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.
Count Substring FAQ
Is this actually hard or does it just sound hard?+
It's medium. The code is short once you see the window pattern. The hard part is not defaulting to nested loops. If you catch the sliding-window hint and know how to shrink a window when a condition breaks, you're home.
How do I know when to shrink vs. expand the window?+
Expand until the condition fails or you've seen all characters. Shrink from the left until the condition is valid again. Move right again. The exact logic depends on the constraint, but the rhythm is always: expand, test, shrink, repeat.
Do I need a hash map for this?+
Almost certainly yes. You'll track character frequencies or some property of the current window in a map or array. This lets you check validity in O(1) instead of O(n).
What's the most common mistake?+
Forgetting to count all valid substrings when you shrink. If a window becomes valid, you might have multiple valid substrings ending at that right pointer. Counting just one per iteration loses the answer.
How much time should I spend on this in the OA?+
15-20 minutes to code and test if you recognize the pattern immediately. If you're stuck on approach after 5 minutes, sketch the brute force, then optimize. Don't thrash.