hackerrank Handshake solution