Ctrl K

Cheapest Mirror String

Easy
You are given a string word of lowercase English letters. In one operation you may replace any letter with any other lowercase English letter. Turn word into a palindrome using as few operations as possible. If several palindromes need that same minimum, return the one that comes first alphabetically (lexicographically).
Example 1
word="river" → 'rever'

The outer pair r/r already matches; the pair i/e differs, so i becomes the smaller e. One change gives "rever".

Example 2
word="zebra" → 'aebea'

The pairs z/a and e/r both differ; each keeps its smaller letter, a and e, giving "aebea".

Example 3
word="noon" → 'noon'

The string is already a palindrome, so nothing changes.

Constraints
  • 1 ≤ len(word) ≤ 1000
  • word consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPalindrome With One Eraser Stroke EasyRise and Fall Lineup EasyPieces Without Shared Letters MediumA Note From Headline Cutouts MediumMirror Chunk Split Hard
loading Python…
Input
word="river"
Expected
'rever'

Run checks the first 3 tests in your browser. Submit checks all 219 tests on the server, hidden ones included.