FastPrepAlphabetically Smallest Palindrome
Problems/Alphabetically Smallest Palindrome

Alphabetically Smallest Palindrome

Microsoft logoMicrosoft● MediumNEW GRADINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

A palindrome reads the same from either direction; for example, ada is a palindrome. You are given a string s of lowercase English letters.

Change the fewest letters possible so that the characters of s can be rearranged to form a palindrome. If multiple palindromes require the same minimum number of changes, return the alphabetically smallest one.

Function

makeAlphabeticallySmallestPalindrome(s: String) → String

Examples

Example 1

s = "azzzbbb"return = "abzbzba"

Optimally, change one z to a to get aazzbbb. These letters can be rearranged to form abzbzba, which is the alphabetically smallest palindrome possible after one change.

Constraints

  • 1 ≤ s.length ≤ 3 × 10^5
  • s consists of lowercase English letters only.

More Microsoft problems

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String makeAlphabeticallySmallestPalindrome(String s) {
      // write your code here
    }
}
Checking account…