String Rearrangement Problem Statement
You are given a string of lowercase characters. The objective is to rearrange (reorder) the string so that no two adjacent characters are identical.
Return the rearranged string. If multiple solutions exist, you can return any of them. If no such rearrangement is possible, return “NO SOLUTION”. If your returned value is correct, the program will output ‘CORRECT’; otherwise, it will output ‘INCORRECT’.
Example:
Input:
str = "aabb"
Output:
"abab" or "baba"
Constraints:
1 <= T <= 100
, where T is the number of test cases.1 <= N <= 10^4
, where N is the length of the string.- Time limit: 1 second.
Input:
The first line of input contains a single integer 'T', representing the number of test cases.
The first and only line of each test case contains a string 'STR'.
Output:
For each test case, return the rearranged string if possible; otherwise, return "NO SOLUTION". CORRECT or INCORRECT will be displayed based on the validity of your output.
Note:
You do not have to print anything. Just implement the function as specified.

AnswerBot
4mo
Given a string of lowercase characters, rearrange it so that no two adjacent characters are identical. Return the rearranged string or 'NO SOLUTION'.
Iterate through the string and count the frequency ...read more
Help your peers!
Add answer anonymously...
Amazon Software Developer interview questions & answers
A Software Developer was asked 1mo agoQ. What is HTML?
A Software Developer was asked 1mo agoQ. What is MySQL?
A Software Developer was asked 2mo agoQ. Given two strings s and t, return true if they are equal when both are typed int...read more
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. What is HTML?
A Software Developer was asked 1mo agoQ2. What is MySQL?
A Software Developer was asked 2mo agoQ3. What is the system design for the cart feature in an e-commerce website?
Top HR questions asked in Amazon Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about a time you had to get to the root cause of a problem
A Software Developer was asked 5mo agoQ2. What are the short-term and long-term goals for the team or organization?
A Software Developer was asked 5mo agoQ3. Why do you want to work at Amazon?
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

