Official algorithmic problem description and constraints.
You have an array π΄ of size π, and a complete weighted graph with π nodes and πβ (πβ1)/2β undirected weighted edges connecting each pair of nodes.
The weight of the edge between node π and node π is β£πβπβ£β maxβ‘(π΄π,π΄π).
The distance between 2 nodes is defined as the minimum sum of weights on a path connecting the 2 nodes.
Find the distance between nodes 1 and π.
Note that β£π₯β£ denotes the absolute value of π₯. For example, β£β7β£=7 and β£4β£=4.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.