Waymo interview question

Hard level Data Structure question related to back-tracking