Goldman Sachs interview question

Leetcode hard. Easy-medium probability questions