string t= abacaba the upsides of the prefix work in positions 1,2,… ,7 are equivalent to [0,0,1,0,1,2,3].    Let f(t) be equivalent to the greatest worth of the prefix capacity of string t over the entirety of its positions. For instance, f(abacaba)=3.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Correct answer will be upvoted else downvoted.

 

 

for string t= abacaba the upsides of the prefix work in positions 1,2,… ,7 are equivalent to [0,0,1,0,1,2,3]. 

 

Let f(t) be equivalent to the greatest worth of the prefix capacity of string t over the entirety of its positions. For instance, f(abacaba)=3. 

 

You are given a string s. Reorder its characters self-assertively to get a string t (the number of events of any character in strings s and t should be equivalent). The worth of f(t) should be limited. Out of all choices to limit f(t), pick the one where string t is the lexicographically littlest. 

 

Input 

 

Each test contains various experiments. The principal line contains the number of experiments t (1≤t≤105). Portrayal of the experiments follows. 

 

The main line of each experiment contains string s (1≤|s|≤105) comprising of lowercase English letters. 

 

It is ensured that the amount of lengths of s over all experiments doesn't surpass 105. 

 

Output 

 

For each experiment print a solitary string t. 

 

The multisets of letters in strings s and t should be equivalent. The worth of f(t), the limit of prefix capacities in string t, should be pretty much as little as could be expected. String t should be the lexicographically littlest string out of all strings fulfilling the past conditions.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education