If we need the longest common sub-sequence of two strings but with the caveat that we are only interested in having all the right letters & frequencies, and not their orders, then dynamic programming isn’t really necessary. This boils down to the problem of finding the largest common subset of the two sets of letters in the two strings.