FastPrepMinimum Replacements for Unequal Adjacent Characters
Problems/Minimum Replacements for Unequal Adjacent Characters

Minimum Replacements for Unequal Adjacent Characters

IBM logoIBM● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IBM online assessment. The report gives the goal of the minimum number of operations but not the allowed edit. For this version, one operation replaces one character with any lowercase English letter. Our version is about 90% the same as the reported question.

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) → int

Examples

Example 1

s = "aab"return = 1

Replace either of the first two a characters with a letter different from its neighbors.

Example 2

s = "aaaa"return = 2

Two replacements can produce abab, and one replacement cannot break all three equal adjacencies.

Example 3

s = "abac"return = 0

Every adjacent pair is already different.

Constraints

  • 1 <= s.length <= 2 * 10^5.
  • s contains 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

IBM interview experiences

  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int minimumReplacements(String s) {
        // Write your code here.
    }
}
Checking account…