Goldman Sachs Interview Question

Leetcode Hard question, similar to get the maximum score