
1. After identifier, each word will consist only of lowercase English letters
2. After the identifier, each word will consist only of numbers.
1. All letter - sentences must come before number- sentences.
2. The letter - sentences must be ordered lexicographically ignoring identifiers. The identifier will be used in case of ties.
3. The number– sentence must be put in their original order of occurrence.
The first line of input contains a single integer 'T', representing the number of test cases or queries to be run.
Then the 'T' test cases follow.
The first line of each test case contains an integer 'N'.
Then 'N' lines follow.
Each line contains a single string, representing the sentence of the array.
For each test case, print 'N' lines.
Then 'N' lines follow.
Each line will contain a single string, representing a sentence of the array in sorted order as mentioned in the description.
Print the output of each test case in a separate line
1 <= T <= 10
0 <= N <= 1000
3 <= |S| <= 100
Where 'T' denotes the number of test cases, 'N' denotes the number of sentences, and |S| denotes the length of sentence, S.
Time Limit: 1 sec
You do not need to print anything, it has already been taken care of. Just implement the given function.
In this solution, the idea is to always pick the smallest letter sentence which is currently available in our list/array and add it to the answer. If there is no letter sentence available in the current list/array then add remaining number sentences to answer.
Below is the implementation of the above approach :
In this solution, the idea is to sort the sentences using the comparator function.
The comparator function is basically used to define the pairwise relationship. In this case, we will define less than (<) relationship among pairs based on the following criteria :
Below is the implementation of the above approach :