Optimal Merge Pattern Problems Leetcode