
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
There are many different solutions for this problem, including a greedy algorithm.
For every cycle, find the most frequent letter that can be placed in this cycle. After placing, decrease the frequency of that letter by one.
Use Priority Queue.