← All problemsSign in

Set To Median

CodeChefRating 2180Open on judge ↗

You are given an integer array $A$ of length $N$. You can do the following operation **at most once**: - Choose a sequence $X_1, X_2, \ldots, X_K$ such that $1 \le X_1 < X_2 < \ldots < X_K \le N$. - Let $V = $ median$^{\dagger}$ of $[A_{X_1}, A_{X_2}, A_{X_3}, \ldots, A_{X_K}]$. - Set $A_{X_i} = V$ for all $1 \le i \le K$. Less formally, we pick one subsequence of $A$ and then replace all it's

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