We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Approach:
As we want Lexicographically smallest possible A, we will try take smaller char first if posiible.
Each char to be taken must have freq = half of freq in given string s.
Now as original A is in reverse order in given string so traverse the string s from last.
store count of each char in unused[] array
store required count for each char in A in required[] array which = half of count of char in unused[] array
Reverse Shuffle Merge
You are viewing a single comment's thread. Return to all comments →
Simple C++ Solution
Approach: As we want Lexicographically smallest possible A, we will try take smaller char first if posiible. Each char to be taken must have freq = half of freq in given string s. Now as original A is in reverse order in given string so traverse the string s from last.
}