FastPrepFastPrep
Problem Brief

Find Encrypted Password (A.K.A Compute Encoded Product Name

NEW GRADOA
See Amazon online assessment and hiring insights

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

    1Example 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.

    2Example 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.

    3Example 3

    Input
    password = "ded"
    Output
    "ded"
    Explanation
    Explanation not found..

    Constraints

    Limits and guarantees your solution can rely on.

  • 1 ≤ |password| ≤ 105
  • password consists of lowercase English letters only.
  • password is a palindrome.
  • public String findEncryptedPassword(String password) {
      // write your code here
    }
    
    Input

    password

    "babab"

    Output

    "abbba"

    Sign in to submit your solution.