🎁 Exclusive Offer! Join our Telegram Channel to get **special discounts** and updates! 🚀

🚀 Struggling with coding interviews? We've got you covered! 💡 Practice real questions, sharpen your skills, and land your dream job! 🎯
Question 18 - 100% Working Solution | Buy Now

Description

3 Live
Company's software team utilizes several algorithms to maintain data integrity, one of which targets the encoding of symmetrical names. Symmetrical names are unique in that they read identically in both directions, similar to palindromes in language parlance. The chief aim of the algorithm is to rearrange the characters in the original symmetrical name according to these criteria: - The rearranged name is a reshuffled version of the original symmetrical name. - The restructured name should be symmetrical as well. - This restructured name should be lexicographically smallest among all its symmetric permutations. Given an initial symmetrical name that contains only lowercase English characters, compute the encoded name. A string s is considered to be lexicographically smaller than the string t of the same length if the first character in s that differs from that in t is smaller, For example, "abcd" is lexicographically smaller than "abdc" but larger than "abad" Note that the output encoded name could match the original name if it's already the smallest lexicographically. Example The original string is letters = "babab". This can be reversed to give "abbba", which is a symmetric rearrangement of the original symmetrical name and is the smallest possible reverse order, It satisfies all the requirements so return the string abbba.

Asked in: Amazon

Image of the Question

Question Image

All Testcases Passed ✔



Passcode Image

Solution


Please login to view the solution