The first line of input contains an integer ‘T,’ denoting the number of test cases. The test cases follow. The first line of each test case contains a number ‘n’ denoting the number of strings. The second line of each test case contains ‘n’ space-separated strings that the monster gave to Ninja.
For each test case, print the strings sorted according to the last character. Print the output of each test case in a separate line.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= T <= 10 1 <= n <= 10^3 1 <= size of string <= 10^2 Where 'T’ is the number of test cases, ‘n’ denotes the number of strings Time Limit: 1 sec
The idea is to reverse all the strings and then sort them in alphabetical order and return the sorted strings back in their original form. We can use a nested loop and compare each string with all the preceding strings to sort the strings.
The steps are as follows: