← Citadel Interview Insights

Citadel·Software Engineer·Online Assessment (OA)·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Citadel SWE assessment, four algorithmic problems, all pretty gnarly. The kind of session where you finish and genuinely aren't sure if you passed or just produced a lot of confident-looking wrong code.

Questions Asked (4)

Q1

Given a binary string and an integer k, count how many non-empty prefixes of the string can be extended (by appending '0's and '1's) to produce a string with exactly k subsequences equal to "10".

Algorithms & Data Structures
Author's notes

This one wrecked me a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem and constraints. Then, derive a formula for the number of '10' subsequences in a binary string and determine the range of achievable counts when extending a prefix. Finally, count prefixes whose achievable range includes k.

Pro tip: Emphasize that the number of '10' subsequences can be adjusted by appending characters, and that the achievable counts form a contiguous interval. This insight simplifies the problem to checking if k lies within that interval for each prefix.

1. Clarify the problem

Confirm that 'extended' means appending any number of '0's and '1's (including zero) to the prefix, and that we count non-empty prefixes. Ensure understanding of subsequences (not substrings).

2. Derive subsequence count formula

For a binary string, the number of '10' subsequences equals the sum over each '1' of the number of '0's after it. Equivalently, it's the number of pairs (i, j) with i < j, s[i]='1', s[j]='0'.

3. Determine achievable counts for a prefix

When extending a prefix, the count can be increased by appending '0's (each '0' adds the number of '1's in the prefix) or by appending '1's followed by '0's. The minimum achievable count is the count in the prefix itself; the maximum is unbounded. Thus, any count ≥ current count is achievable.

4. Count valid prefixes

For each non-empty prefix, compute its current '10' subsequence count. If this count ≤ k, then the prefix can be extended to achieve exactly k (since we can always add more). Count such prefixes.

5. Optimize computation

Iterate through the string once, maintaining the count of '1's seen so far and the current '10' subsequence count. For each character, update these values and check if the current count ≤ k. This yields O(n) time.

Key Points to Mention

  • Definition of subsequence vs substring.
  • Formula for counting '10' subsequences: sum over '1's of number of '0's after it.
  • Monotonicity: appending characters can only increase or maintain the count.
  • Achievable counts form a contiguous interval from current count to infinity.
  • Edge cases: k=0, empty string, all '1's or all '0's.
  • Time and space complexity: O(n) time, O(1) space.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Given an integer array, choose three cut indices to split it into four contiguous segments (possibly empty) and maximize the value computed as sum(s1) - sum(s2) + sum(s3) - sum(s4). Cuts can coincide and can sit at the array boundaries.

Algorithms & Data Structures
Author's notes

Prefix sums make this tractable, and n up to 3000 means O(n^2) is probably fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that the cuts can coincide and be at boundaries, meaning segments can be empty. Then, derive a dynamic programming solution that tracks the maximum value for each prefix and suffix, and combine them to find the optimal split into four segments.

Pro tip: Mention that the problem can be solved in O(n) time by precomputing prefix and suffix maximums, and emphasize that handling empty segments is crucial to avoid off-by-one errors.

1. Clarify the problem

Confirm that cuts can coincide and be at boundaries, so segments can be empty. This means we are effectively choosing three indices i ≤ j ≤ k to define segments [0,i), [i,j), [j,k), [k,n).

2. Define prefix and suffix arrays

Compute prefix sums and then derive arrays for the maximum of sum(s1) - sum(s2) for each possible split point, and similarly for the suffix part sum(s3) - sum(s4).

3. Combine prefix and suffix

Iterate over the middle cut point and combine the best prefix value up to that point with the best suffix value from that point onward to maximize the total expression.

4. Handle edge cases

Consider cases where segments are empty, and ensure the algorithm correctly handles arrays of length 0, 1, or 2, as well as negative numbers.

5. Analyze complexity

State that the solution runs in O(n) time and O(n) space, and discuss potential optimizations to reduce space if needed.

Key Points to Mention

  • Dynamic programming or prefix/suffix maximum arrays
  • Handling empty segments and boundary cuts
  • Time and space complexity analysis
  • Edge cases with small arrays or all negative numbers
  • Proof of correctness or invariant maintenance
  • Potential optimization to O(1) space

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

There are n developers each with a unique skill level from 1 to n. Each developer i has constraints on how many team members can have skill below them and how many can have skill above them. Find the largest subset where every member's constraints are satisfied.

Algorithms & Data Structures
Author's notes

Greedy or binary search on the answer felt like the right direction.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as selecting a subset of developers such that for each selected developer, the number of selected developers with lower skill equals their lower constraint and the number with higher skill equals their upper constraint. This implies that in the selected subset, each developer's rank (position when sorted by skill) must match their constraints. Therefore, the problem reduces to finding the longest subsequence of developers (sorted by skill) where each developer's lower constraint equals their index in the subsequence and upper constraint equals the total size minus index minus one. Use dynamic programming to find the maximum size subset satisfying these conditions.

Pro tip: Clarify that the constraints are with respect to the selected subset, not the entire set. Also, note that the constraints imply a specific position for each developer in the sorted subset, which can be used to filter valid candidates.

1. Understand the constraints

Recognize that for a developer to be in a valid subset of size k, their lower constraint L must equal the number of selected developers with skill less than theirs, and upper constraint U must equal the number with skill greater. Thus, in the sorted subset, their position (0-indexed) must be exactly L, and k - 1 - L must equal U, so k = L + U + 1.

2. Sort developers by skill

Since skill levels are unique from 1 to n, sort the developers by skill level to work with them in increasing order. This allows us to consider subsequences where the relative order is preserved.

3. Filter valid candidates

For each developer, compute the required subset size k = L + U + 1. Only developers with L + U + 1 <= n can potentially be in a valid subset. Also, their position in the sorted subset must be exactly L, so when building the subset, we must place them at index L.

4. Dynamic programming to find largest subset

Use DP where dp[i] represents the maximum size of a valid subset ending with the i-th developer (in sorted order) as the last element. Transition: dp[i] = max(dp[j] + 1) for j < i if developer i can be placed after developer j in a valid subset. Specifically, if we include developer i, the total size k must be L_i + U_i + 1, and developer i must be at position L_i in the subset. This means the number of selected developers before i must be exactly L_i. So we need to find a subsequence of length L_i ending at some j < i, and then append i. Thus, we can maintain for each possible length the best ending index, or use a DP that tracks the maximum size for each position.

5. Optimize and return result

The DP can be optimized by noting that for each developer, we only care about subsets of size exactly L_i before them. We can maintain an array best[length] = minimum ending skill (or index) for a valid subset of that length. Then for each developer, if there exists a valid subset of length L_i with ending index < i, we can form a subset of size L_i + U_i + 1. Update best[L_i + U_i + 1] if this ending index is smaller. Finally, the answer is the maximum length for which a valid subset exists.

Key Points to Mention

  • The constraints are relative to the selected subset, not the entire set of developers.
  • For a developer to be in a valid subset of size k, their position in the sorted subset must be exactly their lower constraint L, and k = L + U + 1.
  • Sorting developers by skill simplifies the problem to finding a subsequence with specific positional constraints.
  • Dynamic programming can be used to find the longest valid subsequence, where state can be the length of the subset or the last included developer.
  • Optimization: maintain the minimum ending index for each possible subset length to efficiently check if a developer can be appended.
  • Edge cases: developers with L + U + 1 > n cannot be in any valid subset; also, multiple developers may have the same required position, but only one can occupy that position in a given subset.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

You have an array of memory block values. You can increment any element as long as it stays below n-1. After any sequence of operations, find all distinct MEX values that are achievable, returned in ascending order.

Algorithms & Data Structures
Author's notes

Easier than it looked once I realized the cap at n-1 bounds how much you can shift values around.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and define MEX precisely. Then, analyze how incrementing elements affects the set of present values and the MEX. Derive conditions for achievable MEX values and implement an efficient algorithm to collect them.

Pro tip: Demonstrate strong problem-solving by discussing edge cases like duplicate values, already high MEX, and the impact of the increment limit. Also, mention time and space complexity upfront to show efficiency awareness.

1. Clarify the problem

Restate the problem in your own words and confirm details: array length, value range, operation constraints, and definition of MEX. Ask clarifying questions if needed.

2. Analyze operation impact

Determine how incrementing elements (up to n-1) can change the presence of values. Identify which values can be introduced or removed and how that affects MEX.

3. Derive achievable MEX conditions

Formulate necessary and sufficient conditions for a MEX value m to be achievable. Consider the counts of each value and the ability to fill gaps up to m-1.

4. Design algorithm

Outline an algorithm to compute all achievable MEX values efficiently, e.g., by sorting, using frequency arrays, or greedy checks. Aim for O(n log n) or O(n) time.

5. Test and validate

Walk through small examples and edge cases to verify the logic. Discuss potential pitfalls and how to handle them.

Key Points to Mention

  • Definition of MEX and its significance in array problems.
  • The constraint that elements can only be incremented, not decremented, and must stay below n-1.
  • The role of duplicates and how they can be used to fill missing values.
  • The maximum possible MEX is n (if all 0..n-1 are present), but constraints may limit it.
  • Efficiency considerations: avoid brute-force simulation; use frequency counts and prefix sums.
  • Edge cases: empty array, all elements already high, array with all same values.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.