Sort Array of Strings Problem Statement

Given an array of strings ARRSTR[] of size N, and a character C, your task is to sort the ARRSTR[] array according to a new alphabetical order that starts with the given character C.

Input:

The first line contains an integer 'T', representing the number of test cases.
Each test case contains:
- An integer 'N' and a character 'C'.
- A sequence of 'N' space-separated strings that are elements of the array.

Output:

For each test case, output a sequence of 'N' space-separated strings sorted according to the new alphabetical order.

Example:

Input:
2
3 d
apple banana cherry
4 w
dog eagle apple frog

Output:
cherry apple banana
apple dog eagle frog

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 1000
  • 'C' is a lowercase English alphabet
  • 1 <= |ARRSTR[i]| <= 9 for 1 <= i <= N

Note:

You do not have to print anything in your implementation. Just return the sorted array.
AnswerBot
4mo

Sort an array of strings based on a new alphabetical order starting with a given character.

  • Iterate through the array of strings and compare each string with the given character to determine the new or...read more

Help your peers!
Select
Add answer anonymously...

Amadeus Software Developer interview questions & answers

A Software Developer was asked Q. Write code to print the Fibonacci series.
A Software Developer was asked Q. What is lazy loading?
A Software Developer was asked Q. Given two strings s and t, return true if t is an anagram of s, and false otherw...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Write code to print the Fibonacci series.
A Software Developer was asked Q2. What is lazy loading?
A Software Developer was asked Q3. Euler’s Totient Function Problem Statement Given an integer N, your task is to d...read more
Amadeus Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits