Citadel software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
DAG Order Validator Given a Directed Acyclic Graph (DAG) and a list of nodes, determine if the list represents a valid topological sort...
Input: Graph (nodes and edges)Expression Evaluator You need to design and implement an expression evaluator that parses and computes mathematical expressions formatted in...
Input: StringKnight Moves on Phone This problem is split into two parts.
Input: ListPrice Change Aggregator You are building a system to aggregate price updates from multiple feeds to reconstruct the price history of an asset.
Input: ListVisit All Cities You are given a list of airline tickets where each ticket represents a directed edge from a departure airport to an arrival...
Input: Graph (nodes and edges)n users (indexed 0 to n - 1) and a list of existing friendships (undirected...Input: ArrayMinimum Sum Tree Path
Input: Binary treeDial Pad Knight Paths
Input: Number(s)Subsequence Goodness Values
Input: ArraySliding Window Top K
Input: Array of integersPrice Stream Merger
Input: ListPandigital Addition Count
Input: Integer(s)Closest Point Pair
Input: ListFlight Itinerary Planner
Input: Graph (nodes and edges)Process Schedule Counter
Input: List[CodeSignal] Common Free Slot
Input: List[CodeSignal] Stable Server Segments
Input: Arraykind, server, seconds, and request_interval. In this part, kind is always "upgrade" and server is either "A" or "B".seconds across records for each server. Records requesting "0" seconds add no work. Every record for the same server has the same positive request_interval.d handles requests at seconds d, 2d, 3d, ... and cannot be upgraded during those seconds. An upgrade second outside those multiples completes exactly one second of work.T in which all work can finish. Return an impossible result if no finite schedule exists. If neither server needs work, the answer is 0.O(n + log U) time for this part, where U is the eventual search bound.plan_upgrades(records: list[dict[str, str]])The return type is up to you. The examples use a JSON integer, or null for impossible.Example 1:[
{"kind":"upgrade","server":"A","seconds":"2","request_interval":"2"},
{"kind":"upgrade","server":"A","seconds":"1","request_interval":"2"},
{"kind":"upgrade","server":"B","seconds":"1","request_interval":"3"},
{"kind":"upgrade","server":"B","seconds":"0","request_interval":"3"}
]5
2 + 1 = 3 seconds and B needs 1 + 0 = 1. By time 4, A has only seconds 1 and 3 available. By time 5, assign A seconds 1, 3, and 5, and B second 2, so the minimum is 5.Part 2 — Blackout policies from multiple infrastructure teamskind: "blackout", source, start, and end, alongside all existing upgrade records.[start, end]. Normal request-interval restrictions still apply.source is an audit label, not a priority, and duplicate windows have no additional effect.minimum_seconds, capacity, shared_capacity, and blackout_seconds.T, capacity[server] counts seconds in [1, T] that are individually usable by that server, regardless of how much work it needs. shared_capacity counts seconds usable by at least one server, counting each second once. blackout_seconds counts the union of blackout seconds in [1, T], including seconds that were already unavailable due to request handling. Capacities describe opportunities, not an actual allocation.null. For T = 0, both server capacities and both other counts are 0.O(n log n + log U · log(n + 1)) time and O(n) space, including diagnostics.[
{"kind":"upgrade","server":"A","seconds":"2","request_interval":"2"},
{"kind":"upgrade","server":"A","seconds":"1","request_interval":"2"},
{"kind":"upgrade","server":"B","seconds":"1","request_interval":"3"},
{"kind":"upgrade","server":"B","seconds":"0","request_interval":"3"},
{"kind":"blackout","source":"exchange_freeze","start":"2","end":"3"}
]{
"minimum_seconds":7,
"capacity":{"A":3,"B":4},
"shared_capacity":4,
"blackout_seconds":2
}7 - floor(7/2) = 4 request-safe seconds; blackout second 3 removes one, leaving {1,5,7}. B has 7 - floor(7/3) = 5 request-safe seconds; blackout second 2 removes one, leaving {1,4,5,7}. Before blackouts, the shared capacity is 7 - floor(7/6) = 6; removing seconds 2 and 3 leaves 4. A can use 1, 5, and 7 while B uses 4. At time 6, A has only two usable seconds, so 7 is minimal. The blackout union contains 2 seconds.Example 3:[
{"kind":"upgrade","server":"A","seconds":"2","request_interval":"2"},
{"kind":"upgrade","server":"A","seconds":"1","request_interval":"2"},
{"kind":"upgrade","server":"B","seconds":"1","request_interval":"3"},
{"kind":"upgrade","server":"B","seconds":"0","request_interval":"3"},
{"kind":"blackout","source":"exchange_freeze","start":"2","end":"4"},
{"kind":"blackout","source":"risk_validation","start":"3","end":"6"}
]{
"minimum_seconds":9,
"capacity":{"A":3,"B":3},
"shared_capacity":4,
"blackout_seconds":5
}[2,6], containing 6 - 2 + 1 = 5 seconds, not 3 + 4 = 7. A's raw capacity is 9 - floor(9/2) = 5; blackout seconds 3 and 5 reduce it to {1,7,9}, or 3. B's raw capacity is 9 - floor(9/3) = 6; blackout seconds 2, 4, and 5 reduce it to {1,7,8}, or 3. The raw shared capacity is 9 - floor(9/6) = 8; only four blackout seconds, 2 through 5, were in that shared capacity, so the result is 4. Second 6 violates both servers' request rules and a blackout rule, but must not be subtracted twice. Assign A seconds 1, 7, and 9 and B second 8. At time 8, A has only two usable seconds, proving minimality.Notes:1 <= start <= end <= 10^18.class OrderBook: def add_order(order_id: str, price: float, quantity: int) -> None: Adds an order to the order book. def remove_order(order_id: str) -> bool: Removes an order from the order book by order ID. def get_current_orders() -> List[Dict[str, Union[str, float, int]]]: Returns a list of current orders. add_order("123", 100.0, 5) None remove_order("123") True 1,000,000. def longest_consecutive(nums: List[int]) -> int:nums = [100, 4, 200, 1, 3, 2]4 [1, 2, 3, 4], which has a length of 4.nums = [0, 3, 7, 2, 5, 8, 4, 6, 1]9 [0, 1, 2, 3, 4, 5, 6, 7, 8], which has a length of 9.0 <= nums.length <= 10^4-10^9 <= nums[i] <= 10^9optimizeConcurrency that takes a list of trades to process concurrently. Each trade requires an update to a shared orderBook, but the updates should not conflict. Use appropriate data structures to minimize locking and waiting.def optimizeConcurrency(trades: List[Dict[str, int]]) -> List[Optional[int]]: def updateOrderBook(trade: Dict[str, int]) -> None: trades = [{'id':1, 'amount':100}, {'id':2, 'amount':200}, {'id':1, 'amount':150}] None trades = [{'id':3, 'amount':300}, {'id':4, 'amount':400}] None 1 <= trades.length <= 1000 1 and 10000.100 concurrent updates.class OrderBookdef add_order(self, order_id: str, price: float, quantity: int, order_type: str) -> None:def remove_order(self, order_id: str) -> None:def get_best_buy(self) -> Tuple[float, int]:def get_best_sell(self) -> Tuple[float, int]:add_order('1', 100.0, 10, 'buy')Noneadd_order('2', 105.0, 5, 'sell')Noneget_best_buy() should return (100.0, 10) and get_best_sell() should return (105.0, 5).1 <= order_id <= 10^5add_order and remove_order may occur, but please ensure consistency in retrieval methods.def min_steps(graph: List[List[int]], start: int, target: int) -> int: graph = [[1,2],[2],[3],[4],[]], start=0, target=4 3 graph = [[1],[2],[3],[4],[5],[]], start=0, target=5 5 100 nodes. 10 outgoing edges. 0 <= start, target < 100 def shortest_time(venues: List[Tuple[int, int, int]], source: int, target: int) -> int:venues = [(0, 1, 5), (0, 2, 10), (1, 2, 2), (2, 3, 1)], source = 0, target = 3 8 0 -> 1 -> 2 -> 3 with a total time of 5 + 2 + 1 = 8.venues = [(0, 1, 8), (1, 3, 6), (0, 2, 7), (2, 3, 2)], source = 0, target = 3 9 0 -> 2 -> 3 with a total time of 7 + 2 = 9.1 <= len(venues) <= 1000 0 <= venue index < 100 def shortest_path(graph: Dict[int, List[Tuple[int, float]]], source: int, target: int) -> float:graph = {0: [(1, 2.0), (2, 4.0)], 1: [(2, 1.0)], 2: []} 3.0 graph = {0: [(1, 10.0)], 1: [(2, 5.0)], 2: [(3, 1.0)], 3: []} 16.0 1 <= len(graph) <= 1000 <= source, target < len(graph) add_rate(base, quote, rate) proposes the relationship 1 unit of base = rate units of quote. Accepted relationships support reciprocal and transitive conversions. Rates are synthetic inputs, not executable market quotes; ignore spreads, fees, timestamps, and rounding to currency minor units.abs(rate - implied_rate) <= 1e-9 * max(rate, implied_rate). Return true for a consistent proposal but retain the existing implied relationships. Return false for an inconsistent proposal, without adding any currencies or changing any implied relationships.1.0, even if that currency is unknown: a consistent proposal registers the currency, while an inconsistent one does not.get_rate and convert return null when either currency is unknown or the currencies are disconnected. A known currency converts to itself at rate 1.0; an unknown currency does not. Conversion is linear: converted_amount = amount * implied_rate.ValueError, and invalid insertions must not change the book. Validate all arguments before checking connectivity.CurrencyConverter() — construct an empty book.add_rate(base: str, quote: str, rate: float) -> bool — accept or reject a proposed relationship according to the rules above.get_rate(base: str, quote: str) -> Optional[float] — return the implied quote units per base unit, or None if unavailable.convert(base: str, quote: str, amount: float) -> Optional[float] — convert an amount, or return None if unavailable.currencies() -> List[str] — return all registered identifiers in ascending lexicographic order.[ ["add_rate", "USD", "EUR", 0.8], ["add_rate", "EUR", "JPY", 150.0], ["get_rate", "USD", "JPY"], ["convert", "JPY", "USD", 24000.0], ["add_rate", "USD", "JPY", 121.0], ["get_rate", "USD", "JPY"], ["currencies"] ]
[true, true, 120.0, 200.0, false, 120.0, ["EUR", "JPY", "USD"]]
0.8 * 150 = 120 JPY, so 24000 / 120 = 200 USD. The proposed rate of 121 contradicts the established snapshot and is rejected.Example 2:[ ["get_rate", "USD", "USD"], ["add_rate", "CHF", "CHF", 2.0], ["currencies"], ["add_rate", "USD", "EUR", 0.5], ["add_rate", "GBP", "JPY", 4.0], ["convert", "USD", "JPY", 10.0], ["add_rate", "EUR", "GBP", 2.0], ["convert", "USD", "JPY", 10.0], ["add_rate", "CHF", "CHF", 1.0], ["convert", "CHF", "CHF", 7.0] ]
[null, false, [], true, true, null, true, 40.0, true, 7.0]
0.5 * 2 * 4 = 4 JPY, so ten USD converts to 40 JPY. Registering CHF with a self-rate of 1 permits identity conversion.Constraints1e12; proposed rates and all implied ratios remain between 1e-12 and 1e12.1e-9 and absolute tolerance 1e-9; proposal acceptance uses only the relative formula specified above.currencies() method.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free