Reported July 2024
Citadel

Count Stable Segments

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

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

Citadel asked this in July 2024, and it's a real pattern-matcher. You get an array and need to count segments where some stability property holds. The catch is figuring out what 'stable' means from context or examples, then building a solution that doesn't time out on large inputs. If you blank on the exact definition, StealthCoder will read the problem statement off your screen and hand you the pattern in seconds.

Pattern and pitfall

Stable segments typically mean contiguous subarrays meeting a constraint: all elements within a range, no duplicates, sorted order, or a similar invariant. The naive approach is O(n^3), checking every pair of indices and validating the constraint. You need to optimize to O(n^2) or better using a sliding window or two-pointer scan. Common pitfall: misreading what 'stable' means and building the wrong validation logic. Another trap is forgetting edge cases like single-element segments or empty arrays. When you're live in the OA and the problem statement is dense or vague, StealthCoder is your safety net to parse it fast and suggest the right scan pattern before you code.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Count Stable Segments 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Citadel reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Stable Segments FAQ

What counts as a 'stable' segment?+

The problem statement will define it. Common meanings: all elements in range [min, max], no duplicates in the window, monotonic order, or sum within bounds. Read the examples closely. If two segments both satisfy the condition, they both count toward your total.

Will a brute force O(n^2) or O(n^3) pass?+

Depends on array size. For n under 5000, O(n^2) usually passes. Over 10000, you may need sliding window or two-pointer to hit O(n) or O(n log n). Check the examples for scale hints.

How do I handle overlapping segments?+

Count them all. If indices 0-2 and 1-3 both satisfy the condition, both are counted. You're not partitioning, you're enumerating. Loop through all start and end pairs.

Is this a dynamic programming problem?+

Unlikely. It's a counting problem. DP appears if you need to track state (like 'longest stable segment' or 'max sum'). Pure counting usually means nested loops with a fast inner validation.

What's the most common mistake Citadel candidates make?+

Misinterpreting the stability rule from the problem text, then building the right algorithm for the wrong constraint. Re-read the examples twice. Code the validation function first, test it on the examples, then wrap the loop.

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

OA at Citadel?
Invisible during screen share
Get it