Google Interview Question

How to connect nodes that randomly appear.