PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Citadel

Implement array merge, round-robin scheduler, and trading simulator

Last updated: Mar 29, 2026

Quick Overview

This multipart problem evaluates algorithmic problem solving and systems-design competencies including in-place array manipulation, queue-based scheduling, and event-driven trading simulation, while testing API/interface specification, edge-case handling, and time/space complexity analysis.

  • medium
  • Citadel
  • Coding & Algorithms
  • Software Engineer

Implement array merge, round-robin scheduler, and trading simulator

Company: Citadel

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given three independent coding prompts. For each prompt, clearly define your function/class interfaces, handle edge cases, and analyze time/space complexity. ## 1) Merge sorted arrays in-place Given two **non-decreasing** integer arrays: - `nums1` of length `m + n`, where the first `m` elements are valid and the last `n` elements are placeholders. - `nums2` of length `n`. Merge `nums2` into `nums1` so that `nums1` becomes a single sorted array. **Inputs** - `nums1: int[]`, `m: int` - `nums2: int[]`, `n: int` **Output** - Modify `nums1` in-place. **Constraints (typical interview scale)** - `0 ≤ m, n ≤ 2e5` - Values fit in 32-bit signed integer. ### Follow-up - How would you merge **three** sorted arrays (`A`, `B`, `C`) into one sorted array? - How would you merge them while also **removing duplicates** (i.e., output strictly increasing values)? --- ## 2) Implement a round-robin task scheduler Implement a round-robin CPU/task scheduler with a fixed time quantum `q`. Each task has: - `id` (string/int) - `arrivalTime` (non-negative integer) - `burstTime` (positive integer total runtime required) Scheduling rules: 1. Tasks enter the ready queue at their `arrivalTime`. 2. The scheduler repeatedly takes the next task from the head of the queue and runs it for `min(q, remainingTime)`. 3. If the task finishes, it leaves the system. 4. If not finished, it goes to the back of the queue. 5. Tasks that arrive while another task is running should be enqueued as soon as they arrive (but do not preempt the current time slice). **Output** Return the execution trace as a list of segments like: - `(taskId, startTime, endTime)` Include idle time segments if the CPU is idle. --- ## 3) Simulate a simplified stock trading system Design and implement a simplified in-memory trading simulator that processes a time-ordered stream of events. Each event is one of: - `DEPOSIT amount` - `BUY symbol qty price` - `SELL symbol qty price` Rules: - Start with zero cash and zero positions. - A `BUY` decreases cash by `qty * price` and increases position for `symbol` by `qty`. - A `SELL` increases cash by `qty * price` and decreases position by `qty`. - Reject any `BUY` that would make cash negative. - Reject any `SELL` that would make the position for that symbol negative. **Output** After processing all events, return: - final cash balance - final positions per symbol - list of rejected events (or their indices) **Follow-ups (optional, if time allows)** - Add average cost basis per symbol. - Add realized P&L using FIFO or average cost.

Quick Answer: This multipart problem evaluates algorithmic problem solving and systems-design competencies including in-place array manipulation, queue-based scheduling, and event-driven trading simulation, while testing API/interface specification, edge-case handling, and time/space complexity analysis.

Related Interview Questions

  • Implement a single-producer multi-consumer ring buffer - Citadel (medium)
  • Sort a Nearly Sorted Array - Citadel (hard)
  • Compute BBO and NBBO from order data - Citadel (medium)
  • Design dynamic weighted random sampling with updates - Citadel (medium)
  • Compute maximum later-earlier difference - Citadel (medium)
Citadel logo
Citadel
Jan 22, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
10
0
Loading...

You are given three independent coding prompts. For each prompt, clearly define your function/class interfaces, handle edge cases, and analyze time/space complexity.

1) Merge sorted arrays in-place

Given two non-decreasing integer arrays:

  • nums1 of length m + n , where the first m elements are valid and the last n elements are placeholders.
  • nums2 of length n .

Merge nums2 into nums1 so that nums1 becomes a single sorted array.

Inputs

  • nums1: int[] , m: int
  • nums2: int[] , n: int

Output

  • Modify nums1 in-place.

Constraints (typical interview scale)

  • 0 ≤ m, n ≤ 2e5
  • Values fit in 32-bit signed integer.

Follow-up

  • How would you merge three sorted arrays ( A , B , C ) into one sorted array?
  • How would you merge them while also removing duplicates (i.e., output strictly increasing values)?

2) Implement a round-robin task scheduler

Implement a round-robin CPU/task scheduler with a fixed time quantum q.

Each task has:

  • id (string/int)
  • arrivalTime (non-negative integer)
  • burstTime (positive integer total runtime required)

Scheduling rules:

  1. Tasks enter the ready queue at their arrivalTime .
  2. The scheduler repeatedly takes the next task from the head of the queue and runs it for min(q, remainingTime) .
  3. If the task finishes, it leaves the system.
  4. If not finished, it goes to the back of the queue.
  5. Tasks that arrive while another task is running should be enqueued as soon as they arrive (but do not preempt the current time slice).

Output Return the execution trace as a list of segments like:

  • (taskId, startTime, endTime)

Include idle time segments if the CPU is idle.

3) Simulate a simplified stock trading system

Design and implement a simplified in-memory trading simulator that processes a time-ordered stream of events.

Each event is one of:

  • DEPOSIT amount
  • BUY symbol qty price
  • SELL symbol qty price

Rules:

  • Start with zero cash and zero positions.
  • A BUY decreases cash by qty * price and increases position for symbol by qty .
  • A SELL increases cash by qty * price and decreases position by qty .
  • Reject any BUY that would make cash negative.
  • Reject any SELL that would make the position for that symbol negative.

Output After processing all events, return:

  • final cash balance
  • final positions per symbol
  • list of rejected events (or their indices)

Follow-ups (optional, if time allows)

  • Add average cost basis per symbol.
  • Add realized P&L using FIFO or average cost.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Citadel•More Software Engineer•Citadel Software Engineer•Citadel Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.