How to solve DNAMG?

Here’s the question :

and my solution in python :
https://www.codechef.com/viewsolution/42927205

My approach :
After taking the sample dna input string in an array (db) sort them so they are lexicographically smallest and then check each of their count against the dna sample input.

My code gives for 1st case but fails for other and there isn’t any case that I can think of in which it fails.
Thanks in advance !