FunctionRacerProblemsRace

Fixes to Make a Mirror

BeginnerTwo pointersPython, JavaScript, TypeScript, Java, C++

You may replace any character of s with any other character. Return the fewest replacements needed so that s reads the same from left to right as from right to left.

Compare the first character with the last, the second with the second to last, and so on; every pair that differs costs exactly one replacement, and the middle character of an odd-length string needs no partner. The empty string needs 0 replacements.

Example 1

s "abca"
returns 1

The pairs are (a, a) and (b, c); only the second one differs.

Example 2

s "abcd"
returns 2

Both pairs (a, d) and (b, c) differ.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems