Align Technology Interview Question

Handshake problem from leetcode .