Minimum Replacements for Unequal Adjacent Characters
Updated
Problem 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 Online Assessment questions
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Maximum Compatible Time WindowsOA · Seen Oct 2026
- Last Object Exit TimeOA · Seen Oct 2026
- Query Type Frequency WindowOA · Seen Oct 2026
- Get Triplet CountOA · Seen Oct 2026
Similar questions at other companies
- Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
- Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions
- Prepare NotificationMicrosoft · OAMicrosoft interview questions
- Minimum Changes for Distinct Adjacent CharactersHeadlands Technologies · OAHeadlands Technologies interview questions
- Largest Number With Even Digit FrequenciesDRW · OADRW interview questions
- Crop Text at a Whole-Word BoundaryAmerican Express · OAAmerican Express interview questions
- Minimum Flips for Even Binary RunsJP Morgan Chase · OAJP Morgan Chase interview questions
- Missing WordsVanguard · OAVanguard interview questions
- Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions
- Smallest String After at Most One DeletionLSEG · OALSEG interview questions