Problem · String
Minimum Replacements for Unequal Adjacent Characters
Learn this problemProblem statement
Given a lowercase string s, return the minimum number of replacement operations needed so that every pair of adjacent characters is different.
In one operation, choose one index and replace its character with any lowercase English letter. Insertions and deletions are not allowed.
Function
minimumReplacements(s: String) → intExamples
Example 1
s = "aab"return = 1Replace either of the first two a characters with a letter different from its neighbors.
Example 2
s = "aaaa"return = 2Two replacements can produce abab, and one replacement cannot break all three equal adjacencies.
Example 3
s = "abac"return = 0Every adjacent pair is already different.
Constraints
1 <= s.length <= 2 * 10^5.scontains only lowercase English letters.
More IBM problems
- Get Maximum AmountOA · Seen Jul 2026
- String-Pair Frequency SimilarityOA · Seen Jul 2026
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026