Approach hintTry it first, then revealHide
Closing a pair as early as possible keeps its length small, so decide each missing character by whether an unmatched ( is currently open. A stack of opening positions then gives the distance of every pair.