I hv first found the max freq element then i hv calculated max no. of gaps possible between 2 such element then i hv filled all elements with this gap whenevr an empty index is found.
Try Solving this question using std::count() . Compare the frequencies of each key and the length of the given string .
Your code is failing on the test case
The correct answer is
or something of this pattern