Minimum Team Size Covering All Talents
Problem n students stand in a row; student j has talent talent[j] ∈ [1, talentCount]. A valid group is a contiguous block containing every talent at least once. For each start index i, compute res[i] = minimum group size starting at i (-1 if impossible).
Input / Output
- Input: int array talent, int talentCount.
- Output: int array res of length n.
Constraints
- n up to 10^5 — computing each start independently (O(n^2)) is the trap; the intended solution is O(n) amortized.
Example
- talent = [1,2,1,3,2], talentCount = 3 → res = [4,3,3,-1,-1] (from i=0 the block [1,2,1,3] covers {1,2,3}).
asked …