Description
Solutions
Submission
Find Encrypted Password 🍅
🔥 FULLTIME

The developers at Amazon employ several algorithms for encrypting passwords. In one algorithm, the developers aim to encrypt palindromic passwords. Palindromic passwords are ones that read the same forward and backward.

The algorithm rearranges the characters to have the following characteristics:

  • It is a rearrangement of the original palindromic password.
  • It is also a palindrome.
  • Among all such palindromic rearrangements, it is the lexicographically smallest.
  • Given the original palindromic password that consists of lowercase English characters only, find the lexicographically smallest palindrome.

    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 encrypted password might be the same as the original password if it is already lexicographically smallest.

    Function Description

    Complete the function findEncryptedPassword in the editor.

    findEncryptedPassword has the following parameter:

    • string password: the original palindromic password

    Returns

    string: the encrypted password

    Example 1:

    Input:  password = "babab"
    Output: "abbba"
    Explanation:
    It can be rearranged to form abbba, which is both a rearrangement of the original password and the lexicographically smallest palindrome. abbba satisfies all the requirements so we can boldly abbba.

    Example 2:

    Input:  password = "yxxy"
    Output: "xyyx"
    Explanation:
    Rearrange the original password to form "xyyx", which is also a palindrome and is the smallest possible rearrangement.

    Example 3:

    Input:  password = "ded"
    Output: "ded"
    Explanation:
    Explanation not found..
    Constraints:
    • 1 ≤ |password| ≤ 105
    • password consists of lowercase English letters only.
    • password is a palindrome.
    Thumbnail 0
    Thumbnail 1
    Testcase

    Result
    Case 1

    input:

    output: