← Citadel Interview Insights

Citadel·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Citadel software engineer interview that centered on array merging, starting from the classic two-array problem and then pushing into a three-array variant with deduplication. The algorithmic depth ramps up faster than you'd expect from what looks like a warmup question.

Questions Asked (3)

Q1

Given two sorted arrays where the first has extra capacity at the end to hold both arrays' elements, merge the second into the first in-place and return it sorted. Solve it in O(m+n) time.

Algorithms & Data Structures
Author's notes

The two-pointer-from-the-end trick is the whole point here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a three-pointer technique starting from the end of both arrays to merge in-place without overwriting unprocessed elements. Compare elements from the back and place the larger one at the end of the first array, moving pointers accordingly. This achieves O(m+n) time and O(1) extra space.

Pro tip: Clarify that the first array has exactly m valid elements and m+n total capacity, and that m and n are given. Mention that merging from the end avoids shifting elements and is optimal for in-place merging.

1. Understand the problem and constraints

Confirm that the first array has length m+n with the last n slots empty, and both arrays are sorted. The goal is to merge in-place in O(m+n) time.

2. Initialize pointers

Set three pointers: i = m-1 (last valid element in first array), j = n-1 (last element in second array), and k = m+n-1 (last position in first array).

3. Merge from the end

While i >= 0 and j >= 0, compare nums1[i] and nums2[j]. Place the larger at nums1[k], then decrement the corresponding pointer and k.

4. Handle remaining elements

If any elements remain in nums2 (j >= 0), copy them into nums1[0..k]. If elements remain in nums1, they are already in place.

5. Return the merged array

The first array now contains all elements sorted. Return it (or its reference).

Key Points to Mention

  • Time complexity: O(m+n) because each element is processed once.
  • Space complexity: O(1) extra space since merging is done in-place.
  • Three-pointer technique: i, j, k starting from the ends.
  • Comparison order: start from the largest elements to avoid overwriting.
  • Edge cases: one array empty, all elements of one array smaller than the other.
  • Stability: not required for this problem, but the algorithm preserves relative order of equal elements from the first array.

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

Q2

Extend the previous problem to merge three sorted arrays and remove any duplicates so the final result is strictly increasing.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where it got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the input arrays are sorted and may contain duplicates, then propose a k-way merge using a min-heap of iterators or a simpler three-pointer approach, skipping duplicates as you go. Emphasize O(N) time where N is total elements and O(1) extra space (excluding output) for the three-pointer method, and discuss trade-offs with heap-based approach for scalability.

Pro tip: After presenting your solution, mention that for three arrays a heap is overkill and a three-pointer approach is more efficient and simpler, showing you understand when to avoid unnecessary data structures. Also, proactively discuss edge cases like empty arrays and all duplicates.

1. Clarify requirements and constraints

Confirm that the input arrays are sorted, may contain duplicates, and that the output should be strictly increasing. Ask about memory constraints and whether modifying inputs is allowed.

2. Choose the right algorithm

For three arrays, a three-pointer approach is optimal: maintain an index for each array, repeatedly pick the smallest current element, and advance the corresponding pointer. Skip any element equal to the last added value to remove duplicates.

3. Handle duplicates and edge cases

While merging, compare the current element with the last element in the result; if equal, skip it. Also handle cases where arrays are empty or one array is exhausted early.

4. Analyze complexity and trade-offs

State that time complexity is O(N) where N is total elements, and space is O(1) extra (excluding output). Compare with a heap-based k-way merge which would be O(N log 3) but unnecessary overhead for three arrays.

5. Test with examples

Walk through a small example, e.g., arrays [1,2,2], [2,3,4], [4,5,5] to demonstrate duplicate removal and correct merging. Mention potential pitfalls like integer overflow or non-integer types if relevant.

Key Points to Mention

  • Three-pointer technique for merging sorted arrays
  • Duplicate removal by comparing with last added element
  • Time complexity O(N) and space complexity O(1) extra
  • Trade-offs between three-pointer and heap-based k-way merge
  • Edge cases: empty arrays, all duplicates, one array exhausted
  • Stability and in-place vs. new array considerations

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

Q3

Compare using a min-heap for k-way merging versus sequentially merging two arrays at a time. How does deduplication interact with each strategy?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Mostly a discussion question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by contrasting the time and space complexity of the two approaches: min-heap k-way merge is O(N log k) where N is total elements and k is number of arrays, while sequential pairwise merging can be O(N k) in the worst case. Then discuss how deduplication can be integrated into each strategy, noting that the min-heap naturally allows efficient duplicate skipping during merge, whereas sequential merging may require additional passes or data structures. Conclude with trade-offs in terms of implementation complexity, memory usage, and suitability for different scenarios.

Pro tip: Mention that in practice, if k is small or arrays are already sorted with little overlap, sequential merging might be simpler and fast enough, but for large k or when deduplication is critical, the min-heap approach scales better. Also, note that deduplication can be done on-the-fly with a min-heap by comparing the popped element with the last output, avoiding extra memory.

1. Define the problem and assumptions

Clarify that we are merging k sorted arrays into one sorted array, and deduplication means removing duplicate values across arrays. Assume arrays are sorted and may contain duplicates.

2. Analyze min-heap k-way merge

Explain that a min-heap of size k stores the current smallest element from each array. Repeatedly extract the minimum, add to output, and insert the next element from the same array. Time complexity: O(N log k), space O(k) for heap plus output.

3. Analyze sequential pairwise merging

Describe merging arrays two at a time (e.g., merge array 1 and 2, then result with 3, etc.). Time complexity: O(N * k) in worst case if always merging a growing result with a new array, or O(N log k) if using a balanced merge tree. Space O(N) for intermediate results.

4. Integrate deduplication

For min-heap: when extracting min, compare with last added element; if equal, skip. For sequential: during each merge, skip duplicates by comparing with last output; but duplicates across non-adjacent merges may require additional checks or a final dedup pass.

5. Compare trade-offs and conclude

Summarize that min-heap is more efficient for large k and allows easy dedup, while sequential merging is simpler but may be slower and require extra steps for dedup. Choose based on constraints.

Key Points to Mention

  • Time complexity: O(N log k) for min-heap vs O(N k) or O(N log k) for sequential depending on merge strategy.
  • Space complexity: min-heap uses O(k) extra space; sequential merging may use O(N) for intermediate arrays.
  • Deduplication in min-heap: compare popped element with last output, skip if duplicate.
  • Deduplication in sequential merging: need to handle duplicates during each merge and possibly across merges.
  • Implementation complexity: min-heap requires a priority queue and careful index tracking; sequential merging is simpler but may need multiple passes.
  • Scalability: min-heap scales better with large k; sequential merging may be preferable for small k or when memory is constrained.

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