Reverse Shuffle Merge

  • + 0 comments

    I agree. The solution, though a very good one, is hardly readable. The overusage of #defines is really weird.

    The brute force approach timed out for me even with correct answers, so I prefer the editorial approach. Roughly it goes like this

    For each substring, create a new freq array(O(n2)). Create a map with the key = hash of freqarray. The hash has to be decent enough so that 'abb' and 'aab' do not cause collission. The value part is the number of substrings that have that same key.
    Once the map is created, we need to just iterate it through once to find the number of substrings which have the same freq map.

    Hope that was clear enough.