Cloudera Interview Question

a difficult leetcode medium problem