Sed Max
JJ has a magical sequence $A_1, A_2, \ldots, A_N$. The group of high magicians Sed wants to buy this sequence from him. They calculate its cost as follows: - Choose a subarray of length atleast $2$, i.e. a contiguous subsequence $A_l, A_{l+1}, \ldots, A_r$ such that $1 \le l \lt r \le N$. - The cost is the difference between the largest and the second largest element in this subarray (note that
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