LC: 1259. Handshakes That Don't Cross - spiralgo/algorithms GitHub Wiki
1259. Handshakes That Don't Cross:
The Essence:
- Suppose
npeople stand around a circular table like in the picture below. We havek = n/2pairs. - If
Person 1wants to shake hands withPerson X,Xshould be anevennumber. Otherwise, the other handshakes would cross. - When
Person 1shakes hand withPerson X, their1 pairwill split the group into two distinct pairs:j pairsandk-j-1 pairs. - Therefore,
the number of ways these handshakes could occurwill be equal to:numberOfWays(j pairs)*numberOfWays(k-j-1 pairs)

Details:
For a detailed explanation and DP-Catalan Numbers implementation, please refer to: https://github.com/spiralgo/algorithms/pull/378