MerQube interview question

coding question leetcode, do medium to hard