As reported: D. E. Shaw online assessment (2025):
nsoftware components in a circular network,mof them initially infected; each day the lead developer patches one uninfected component (making it permanently immune) and then the bug spreads to every unpatched neighbour of an infected component; find the maximum number of components that can be saved.
n software components are arranged in a circle and labelled 1..n: component i is connected to i − 1 and i + 1, and component n is connected back to 1. Initially the components listed in infected (m distinct labels) are infected.
Every day, in this order:
- The lead developer picks one uninfected component and patches it — it can never be infected.
- Every unpatched, uninfected component that has an infected neighbour becomes infected.
This repeats until the bug can no longer spread. Return the maximum number of components that are never infected (patched or simply never reached), if the developer chooses patches optimally.
Example 1
n = 10, infected = [3,6,8]
Output: 3
The healthy stretch 9, 10, 1, 2 is the longest. Day 1: patch 9 (then 2 gets infected from 3). Day 2: patch 1 (then 10 is safe behind 9 and 1). Components 9, 10, 1 are saved; everything else is infected.
Example 2
n = 6, infected = [2,5]
Output: 1
Constraints: 2 ≤ n ≤ 10^9; 1 ≤ m ≤ min(n, 10^5); infected holds distinct labels in [1, n], in any order.
Code runner format: one JSON value per line: n, then infected. Implement maxSaved(n, infected).