Compute max team size with a core interval
Company: Citadel
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This question evaluates algorithmic problem-solving around interval overlap and time-complexity optimization, measuring the ability to determine the maximum team size given a core interval while reasoning about interval intersections and scalability; it is commonly asked to assess correctness and subquadratic runtime thinking, categorized under Coding & Algorithms and emphasizing practical algorithmic implementation. The follow-up evaluates combinatorics and counting under adjacency constraints with modular arithmetic and efficient handling of large parameters, commonly posed to test recurrence reasoning and scalable counting approaches, falling under combinatorics/dynamic programming and emphasizing conceptual understanding linked to practical algorithmic efficiency.
Part 1: Maximum Team Size With a Core Employee
Constraints
- 0 <= n <= 2 * 10^5
- len(startTime) == len(endTime) == n
- 0 <= startTime[i] <= endTime[i] <= 10^9
- Your algorithm should be better than O(n^2)
Examples
Input: ([2, 5, 6, 8], [5, 6, 10, 9])
Expected Output:
Explanation: Choosing employee 2 with interval [5, 6] gives a team of size 3: [2,5], [5,6], and [6,10].
Input: ([1, 2, 3], [2, 3, 4])
Expected Output:
Explanation: The middle interval [2,3] intersects both neighbors because endpoint touching counts as overlap.
Hints
- For a fixed core interval [s, e], another interval overlaps it exactly when its start is <= e and its end is >= s.
- Sort all start times and all end times separately. Then use binary search to count how many intervals can overlap each employee's interval.
Part 2: Count Valid Process Allocations With No Equal Adjacent Slots
Constraints
- 0 <= n <= 10^9
- 0 <= m <= 10^18
- The answer must be returned modulo 10^9 + 7
- The solution should handle very large m efficiently
Examples
Input: (3, 2)
Expected Output:
Explanation: Choose any of 3 processes for the first slot, then 2 different processes for the second slot: 3 * 2 = 6.
Input: (2, 4)
Expected Output:
Explanation: Only two alternating sequences are possible: [1,2,1,2] and [2,1,2,1].
Hints
- How many choices do you have for the first slot? How many choices remain for each later slot?
- Once you derive the formula, use fast modular exponentiation instead of multiplying in a loop.