Dealpath interview question

Standard Leet code medium problem