Graph Cost
You have an array $A$ of size $N$, and a [complete](https://en.wikipedia.org/wiki/Complete_graph) [weighted](https://en.wiktionary.org/wiki/weighted_graph) graph with $N$ nodes and $\frac{N \cdot (N-1)}{2}$ undirected weighted edges connecting each pair of nodes. The weight of the edge between node $i$ and node $j$ is $|j - i| \cdot \max(A_i, A_j)$. The distance between $2$ nodes is defined as
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