Few Different Elements
Let's call a sequence with length $K$ *good* if there are at most $\frac{K}{2} + 1$ distinct elements in it. For example, the sequence $(3, 3, 2, 1, 3)$ is good, since it contains $3 \le \frac{5}{2} + 1$ distinct elements, while the sequence $(1, 4, 8, 8, 2)$ is not good, since it contains $4 \gt \frac{5}{2} + 1$ distinct elements. You are given a sequence of integers $A_1, A_2, \ldots, A_N$. Y
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