Fixes to Make a Mirror
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
0 <= len(s) <= 60shas lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Two pointers problems
- Flip a StretchBeginner
- Fold and AddBeginner
- Lighten the ShelfBeginner
- Peel Matching EndsBeginner
- Sums of Every WindowBeginner
- Trim the ZerosBeginner
- Written BackwardsBeginner
- Zip Two Sorted ListsBeginner