Reported June 2025
JP Morgansliding window

One Substring Count

Reported by candidates from JP Morgan's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live JP Morgan OA. Under 2s to a working solution.
Founder's read

JP Morgan's One Substring Count is a sliding-window problem that shows up in their June 2025 OA cycle. You're given a string and need to count occurrences of a substring or match a specific pattern within a window. The trap is overthinking the window size or the matching logic. Most candidates either scan too broadly or rebuild state incorrectly. StealthCoder can hand you the window bounds and pattern match logic in real time if you blank on the iteration order.

Pattern and pitfall

The core trick is maintaining a fixed or variable window and tracking what's inside it efficiently. You'll slide left and right pointers, update a counter or hash map as you move, and record valid windows that meet the criteria. The common mistake is recalculating the entire window state on every shift instead of adding and removing one character at a time. If the problem asks for distinct substrings or counts of a specific pattern, a hash set or frequency map inside the window is your shield. StealthCoder spots the window boundaries and can verify your state transitions during the live OA, so you stay on pace even if your first approach feels shaky.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill One Substring Count 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 StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as substring with concatenation of all words. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass JP Morgan's OA.

JP Morgan 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.

One Substring Count FAQ

Is this a 'count all substrings' problem or find specific ones?+

Without the full problem text, assume you're counting substrings that satisfy a condition (e.g., contain exactly one vowel, match a pattern). The sliding window lets you count valid windows efficiently instead of brute force checking every substring pair.

What's the sliding-window trick for substring counting?+

Move the right pointer to expand the window, move the left pointer to shrink it. Update a frequency map or counter with each move. When the window is valid, all substrings ending at right and starting between left and some boundary are valid. Add them to your count without rechecking.

How do I avoid recalculating the window every iteration?+

Use a rolling hash or character frequency map. When you add a character on the right, increment its count. When you remove a character on the left, decrement it. Check validity in O(1) or O(26) time, not O(n).

Does JP Morgan's version have edge cases around empty strings or single characters?+

Almost certainly. Test your window logic when left == right, when the substring is length 1, and when no valid window exists. Don't skip bounds checks; off-by-one errors on window size are common failures.

If I blank on the pattern during the OA, what's my fallback?+

Write a brute-force nested loop first to verify your logic on small cases. It's O(n^2) or O(n^3) but correct. Then optimize to sliding window. JP Morgan values correctness over speed. A slow AC beats a fast WA.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with JP Morgan.

OA at JP Morgan?
Invisible during screen share
Get it