← All problemsSign in

Major Infection

CodeChefRating 2957Open on judge ↗

You are given an array $A$ of length $N$. You can perform the following operation on it: - Choose a non-empty contiguous subarray $A[L\ldots R]$ of $A$ that has a *majority element*$^\dagger$. - Let $M$ be this majority element. Then, set $A_L = A_{L+1} = \ldots = A_R = M$. Find the lexicographically minimum array that can be attained as a result of performing the given operation however many

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