Cloudera interview question

a difficult leetcode medium problem