Mortenson Interview Question

Time I struggled and overcame it.