http://www.nxcoding.com/archives/leetcode-daily-3343-count-balanced-permutations-dp