I was asked this question in a Startup company but I couldn't solve this. Its a variation of Task Schedular problem - https://leetcode.com/problems/task-scheduler/ , but characters can only be arranged in the order as they appear. Meaning, if ABC is the input string, A should be arranged first followed B and C respectively.
Example String : ABBCA , Cool down period : 2
Expected O/P String : AB..BCA
Return result length - 7
Example String2 : AABBCA, Cool down period : 2
Expected O/P : A..A..B..B..CA
Return result length - 14