Trees Are Fun
CodeChefOpen on judge ↗
You are given a tree with $2N$ nodes. Each node $i$ has an associated *value* $A_i$. It is guaranteed that each integer from $1$ to $N$ occurs exactly **twice** in the array $A$. Define a function $F(B)$ for an array $B$ of length $M$ as follows: - Start with a score of $0$. - Repeat until $B$ is empty: 1. Choose any integer $E$ present in $B$. 2. Let $L$ be the leftmost index of $E$ in $B$
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