Maximum Score Subarray
The *score* of an array $B$ of length $M$ is defined as follows: - Let $P$ denote the number of pairs $(i, j)$ such that $1 \leq i \lt j \leq M$ and $B_i = B_j$. - Then, $\text{score}(B) = M - P$. --- You are given an array $A$ of length $N$. Your task is to compute the **maximum** score across all contiguous subarrays of $A$, i.e. compute the quantity $$ \max_{1 \leq L \leq R \leq N} \text{sc
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start