← Citadel Interview Insights

Citadel·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Citadel software engineer interview with a graph/union-find problem. Pretty focused session, one meaty algorithmic question with a clear follow-up on complexity tradeoffs.

Questions Asked (1)

Q1

You have an m x n grid initialized to all water. Given a sequence of positions, each operation flips a cell from water to land. After each operation, return the total number of islands currently in the grid.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Went with union-find pretty quickly, which felt right.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use Union-Find (Disjoint Set Union) to dynamically maintain connected components as cells are added. For each new land cell, increment the island count, then union it with any adjacent land cells, decrementing the count for each successful union. This yields O(1) amortized time per operation with path compression and union by rank.

Pro tip: Mention that Union-Find is optimal here because it handles incremental connectivity efficiently, and briefly compare with BFS/DFS which would be O(m*n) per operation. Also, discuss the trade-off between path compression and union by rank for near-constant time.

1. Clarify the problem and constraints

Confirm that the grid starts as all water, and each operation flips a water cell to land. Ask about grid size, number of operations, and whether positions are guaranteed unique and within bounds.

2. Choose the right data structure

Select Union-Find (Disjoint Set Union) to efficiently track connected components of land cells. Explain why it's better than re-running BFS/DFS after each operation.

3. Design the algorithm

Initialize a DSU for all cells. For each operation, mark the cell as land, increment island count, then check its four neighbors; if a neighbor is land, union the two cells and decrement the count if they were in different sets.

4. Analyze complexity and edge cases

State that with path compression and union by rank, each operation is nearly O(1) amortized, total O(k α(mn)) for k operations. Discuss edge cases like duplicate positions, boundary cells, and no land.

5. Implement and test

Write clean code for DSU with find and union methods, then test with small examples and edge cases to ensure correctness.

Key Points to Mention

  • Union-Find (Disjoint Set Union) with path compression and union by rank for near-constant time operations.
  • Incremental approach: start with zero islands, add land cells one by one, and update count via unions.
  • Neighbor checking: only need to check four adjacent cells (up, down, left, right) for land.
  • Time complexity: O(k α(mn)) where k is number of operations, α is the inverse Ackermann function.
  • Space complexity: O(mn) for the DSU parent and rank arrays.
  • Trade-offs: Union-Find is optimal for dynamic connectivity; BFS/DFS would be O(mn) per operation, too slow for large grids.

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