Anonymous interview question

A Medium leet code problem