Find Encrypted Password (A.K.A Compute Encoded Product Name
Learn this problemProblem statement
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:
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
findEncryptedPassword(password: String) → String
Complete the function findEncryptedPassword in the editor.
findEncryptedPassword has the following parameter:
string password: the original palindromic password
Returns
string: the encrypted password
Examples
Example 1
password = "babab"return = "abbba"Example 2
password = "yxxy"return = "xyyx"Example 3
password = "ded"return = "ded"Constraints
1 ≤ |password| ≤ 105password consists of lowercase English letters only.password is a palindrome.More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026