← Citadel Interview Insights

Citadel·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jul 2026

Summary

Citadel quant researcher interview, got hit with a classic combinatorics/CS problem that I thought I knew but fumbled the complexity analysis on. The follow-up about scaling to huge n was the part that really separated candidates I think.

Questions Asked (3)

Q1

Implement a simulation of the Josephus problem: n people in a circle, eliminate every k-th person starting from person 1, return the surviving position.

Algorithms & Data Structures
Author's notes

I went straight to a list-based simulation and it worked fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (e.g., 1-indexed positions, elimination starting at person 1). Then present both a simulation approach (e.g., using a circular linked list or queue) and an optimal mathematical approach (Josephus recurrence). Finally, discuss time/space complexity and edge cases.

Pro tip: Mention that the mathematical solution runs in O(n) time and O(1) space, which is optimal for large n, and that it's derived from the recurrence J(n,k) = (J(n-1,k) + k) % n. This shows you understand the problem deeply and can optimize beyond brute force.

1. Clarify the problem

Confirm indexing (1-based), elimination order (every k-th person starting from person 1), and that the circle continues until one remains. Ask about constraints (n and k ranges) to decide between simulation and mathematical solution.

2. Describe a simulation approach

Explain how to simulate using a circular data structure (e.g., linked list or queue). For each elimination, skip k-1 people and remove the k-th, repeating until one remains. Mention time complexity O(n*k) or O(n) with a queue.

3. Present the optimal mathematical solution

Introduce the Josephus recurrence: J(1,k) = 0 (0-indexed), J(n,k) = (J(n-1,k) + k) % n. Explain that this computes the survivor's position in O(n) time and O(1) space, and convert to 1-indexed by adding 1.

4. Analyze complexity and edge cases

Compare time/space of both approaches. Discuss edge cases: n=1, k=1, k>n, and large n where simulation is infeasible. Mention that the mathematical solution is preferred for large n.

5. Provide code or pseudocode

Write clean code for the chosen approach, ideally the mathematical one, with comments explaining the recurrence. Test with small examples (e.g., n=5, k=2) to verify correctness.

Key Points to Mention

  • Josephus problem definition and recurrence relation
  • Simulation using circular linked list or queue
  • Mathematical solution with O(n) time and O(1) space
  • Indexing: 0-indexed vs 1-indexed and conversion
  • Time and space complexity analysis for both approaches
  • Edge cases: n=1, k=1, k>n, and large n

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

Q2

Derive and implement the O(n) recurrence solution for the Josephus problem: J(1,k)=0, J(n,k)=(J(n-1,k)+k) mod n, iteratively with O(1) space.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I actually had to think.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the recurrence J(n,k) = (J(n-1,k) + k) mod n, which gives the survivor's position in 0-indexed terms. Then show how to compute it iteratively from n=1 to n, updating a single variable in O(1) space. Finally, implement the loop and discuss time complexity O(n) and space O(1).

Pro tip: Mention that the recurrence works because after the first elimination, the problem reduces to a smaller Josephus problem with a shifted starting point. Also, clarify that the result is 0-indexed; if 1-indexed is needed, add 1 at the end.

1. Define the problem and recurrence

State the Josephus problem: n people in a circle, every k-th person eliminated, find the survivor. Present the recurrence J(1,k)=0 and J(n,k)=(J(n-1,k)+k) mod n, explaining that it gives the 0-indexed position.

2. Explain the intuition behind the recurrence

Describe how after the first elimination, the problem reduces to a smaller instance of size n-1 with a shifted starting point. The shift is k modulo n, leading to the recurrence.

3. Derive the iterative solution

Show that we can compute J(n,k) iteratively by starting with result = 0 for n=1 and looping i from 2 to n, updating result = (result + k) % i. This uses O(1) space and O(n) time.

4. Implement the code

Write a function that takes n and k and returns the survivor's position (0-indexed). Use a simple loop and modular arithmetic. Optionally, add 1 for 1-indexed output.

5. Analyze complexity and edge cases

State that time complexity is O(n) and space is O(1). Discuss edge cases: n=1, k=1, large n, and potential integer overflow (though modulo prevents it).

Key Points to Mention

  • The recurrence relation and its derivation from the reduced subproblem.
  • 0-indexed vs 1-indexed output and how to convert.
  • Iterative implementation with a single variable for O(1) space.
  • Time complexity O(n) and space complexity O(1).
  • Edge cases: n=1, k=1, and large values of n or k.
  • Why the modulo operation is safe and prevents overflow.

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

Q3

When would you prefer the simulation approach versus the recurrence-based approach, and how would you handle the case where n is on the order of 10^9?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Blanked for a second.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem context and the trade-offs between simulation and recurrence-based approaches, focusing on time/space complexity and constraints. Then, for n ~ 10^9, discuss how to optimize using matrix exponentiation or closed-form solutions, and mention practical considerations like modular arithmetic and overflow. Conclude by emphasizing the importance of choosing the right approach based on problem specifics and constraints.

Pro tip: Demonstrate awareness of numerical stability and precision issues when n is large, and suggest using logarithms or modular arithmetic to avoid overflow. Also, mention that in real-world systems, you might combine both approaches or use approximations when exact solutions are infeasible.

1. Clarify the problem and constraints

Ask clarifying questions about the problem domain, input size, required precision, and time/space limits to determine which approach is suitable.

2. Compare simulation vs. recurrence

Discuss when simulation is preferred (e.g., complex systems with no closed form, stochastic processes) versus recurrence (e.g., deterministic, well-defined sequences with efficient computation).

3. Address large n challenges

Explain that for n ~ 10^9, direct simulation or naive recurrence is infeasible; propose optimizations like matrix exponentiation, fast doubling, or closed-form formulas.

4. Discuss implementation details

Mention handling large numbers with modular arithmetic, using efficient data structures, and considering parallelization or approximation if exact results are not required.

5. Conclude with trade-offs and recommendations

Summarize the decision criteria and recommend a hybrid approach or the most practical solution given the constraints.

Key Points to Mention

  • Time and space complexity analysis of both approaches
  • Matrix exponentiation for linear recurrences (e.g., Fibonacci) to achieve O(log n) time
  • Closed-form solutions (e.g., Binet's formula) and their numerical stability issues
  • Modular arithmetic to handle large numbers and avoid overflow
  • When simulation is necessary: stochastic processes, complex interactions, or no known recurrence
  • Practical considerations: memory limits, parallelization, and approximation techniques

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