Good Subsequences
You are given a permutation $p_1, p_2, \ldots, p_N$. Let's denote a contiguous subsequence $p_l, p_{l+1}, \ldots, p_r$ in it by $[l, r]$ and call it *interesting* if $\max(p_l, p_{l+1}, \ldots, p_r) - \min(p_l, p_{l+1}, \ldots, p_r) = r - l$. Next, let's say that two interesting subsequences $[a,b]$ and $[c,d]$ are *nested* if $a \le c \le d \le b$ or $c \le a \le b \le d$, and they are *interl
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