Rearrange String Problem Statement
Given a string ‘S’, your task is to rearrange its characters so that no two adjacent characters are the same. If it's possible, return any such arrangement, otherwise return “not possible”.
Example:
Input:
S = "qaacde"
Output:
"qacade"
Explanation:
In the string "qaacde", originally there are two same adjacent characters. One possible rearrangement where no two adjacent characters are the same is "qacade".
Input:
T
S1
S2
…
ST
Output:
"Yes" if rearrangement is possible, otherwise "No" for each test case.
Constraints:
- 1 <= T <= 10
- 0 <= |S| <= 105
- Time Limit: 1 second.
Note:
No need to print anything; implementation of the function is sufficient.

AnswerBot
4mo
Given a string, rearrange its characters so that no two adjacent characters are the same. Return 'Yes' if possible, 'No' otherwise.
Iterate through the string and count the frequency of each character
U...read more
Help your peers!
Add answer anonymously...
PayPal Full Stack Developer interview questions & answers
A Full Stack Developer was asked Q. Group Anagrams Together Given an array/list of strings STR_LIST, group the anagr...read more
A Full Stack Developer was asked Q. Rearrange String Problem Statement Given a string ‘S’, your task is to rearrange...read more
A Full Stack Developer was asked Q. Divide Two Integers Problem Statement You are given two integers dividend and di...read more
Popular interview questions of Full Stack Developer
A Full Stack Developer was asked Q1. Group Anagrams Together Given an array/list of strings STR_LIST, group the anagr...read more
A Full Stack Developer was asked Q2. Rearrange String Problem Statement Given a string ‘S’, your task is to rearrange...read more
A Full Stack Developer was asked Q3. Divide Two Integers Problem Statement You are given two integers dividend and di...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

