ByteDance interview question

A medium leetcode DP question (leetcode 198)