← All problemsSign in

J - Score Sum

Suppose we have an array $A$ of $N$ elements. We will define a $score$ function on the array $A$ in the following way. Let $d(L, R)$ denote the number of distinct elements in the subarray $[A_L, A_{L + 1}, \ldots, A_R]$. Define $f(L, R) = (R - L + 1) - d(L, R)$, i.e., the length of the subarray from $L$ to $R$ minus the number of distinct elements in it. Consider the pair $(L, R)$ satisfying $

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.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start