Interview problem from Naichen