Sorted Distances
MoEngage has given you an array $A$ consisting of $N$ positive integers. You should perform $Q$ queries of the following two types: - $1$ $i$ $X$ : Set $A_i$ to $X$. - $2$ $L$ $R$ : Find the **minimum** non-negative integer $K$ such that the sequence $[|A_L - K|, |A_{L+1} - K|, \ldots, |A_{R-1} - K|, |A_R - K|]$ is sorted in **non-decreasing** order. Print $-1$ if no such $K$ exists. For each q
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