Sort Array Of Strings

You are given an array of strings 'ARRSTR[]' of size 'N' and a character 'C'. Your task is to sort the 'ARRSTR[]' according to the new alphabetical order that starts with the given character 'C'.

Note:

1) The character ‘C’ is a lowercase English alphabet that is given as input.
2) For example, if the character is 'C' is "d" then, the alphabetical order starts with "d" will look like {d,e,f,....,y,z,a,b,c}.
3) Every string in the array consists of only lowercase English alphabets.
Input Format:
The first line contains an integer 'T', which denotes the number of test cases or queries to be run. Then, the 'T' test cases follow. 

The first line of each test case contains a positive integer 'N' denoting the size of the array and a character 'C', as described in the problem statement.

The second line of each test case contains a sequence of 'N' space-separated strings denoting the elements of the array.
Output Format:
For each test case, print in a new line a sequence of 'N' space-separated strings after sorting according to the new alphabetical order given in the problem.
Output for each test case will be printed in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 100
1 <= N <= 1000
'C' is a lowercase English alphabet. 
1 <= | ARRSTR[i] | <= 9, where 1 <= i <= N.

Time Limit: 1sec
CodingNinjas
author
2y
HashMap Approach

Approach: The idea here is to use a data structure HashMap to store each character’s order in the new alphabetical order, starting with a letter c (given in the problem). Now, start co...read more

Help your peers!
Add answer anonymously...
Amadeus Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter