Computer Science, asked by shrutikatyal0181, 6 months ago

A string of characters including only alphabets (lowercase letters) is provided as an input.
The first task is to compute the frequency of each character appearing in the string. In the output, the characters have to be arranged in the same order as they appear in the input string. Then characters have to be rearranged, such that all the characters having a specific frequency, say , come together.
Let the frequency of a character, lying in between the two characters having same frequency , be . The steps to be followed for getting the desired arrangement are as follows:
If y>x, then shift the character at the end. Ify n 8 o 11 m 4 a 5 t 6 e 10 r 10 h 3 w 1 b 1 u 7 s 6 y 6 i 5 k 1 f 4 d 3 g 2 l 2 c 2 k 1 b 1 w 1 n 8 o 11 m 4 a 5 t 6 e 10 r 10 h 3 d 3 g 2 l 2 c 2 u 7 s 6 y 6 i 5 f 4 k 1 b 1 w 1 n 8 o 11 m 4 a 5 t 6 e 10 r 10 h 3 d 3 g 2 l 2 c 2 u 7 s 6 y 6 i 5 f 4 c 2 l 2 g 2 d 3 h 3 k 1 b 1 w 1 n 8 o 11 m 4 a 5 t 6 s 6 y 6 i 5 f 4 e 10 r 10 u 7

Answers

Answered by Anonymous
1

Answer:

Given a string with repeated characters, the task is to rearrange characters in a string so that no two adjacent characters are same.

Note : It may be assumed that the string has only lowercase English alphabets.

Examples:

Input: aaabc

Output: abaca

Input: aaabb

Output: ababa

Input: aa

Output: Not Possible

Similar questions