Block Interview Question

TO provide an algorithm