FastPrepMinimum Changes for a Beautiful String
Problems/Minimum Changes for a Beautiful String

Minimum Changes for a Beautiful String

Microsoft logoMicrosoft● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft intern online assessment. We keep the rule for neighbors, the operation of replacing one character, the function contract and the example in the report. We added limits and a second example, in four languages. Our version is about 95% the same as the reported question.

A lowercase string is beautiful when the absolute alphabet-index difference between every pair of adjacent characters is greater than 1. Equal letters and consecutive letters are therefore invalid neighbors; a and z are not consecutive.

In one operation, choose any position and replace its character with any lowercase English letter. Return the minimum number of operations needed to make s beautiful.

Function

getMinimumOperationCount(s: String) → int

Examples

Example 1

s = "bddje"return = 1

Changing the second d to f gives bdfje, whose adjacent differences are all greater than one.

Example 2

s = "acaz"return = 0

Every adjacent alphabet-index difference is already at least two.

Constraints

  • 1 <= s.length <= 100000.
  • s contains only lowercase English letters.

Source note: The source image is a source-neutral excerpt of the author-reported prompt.

More Microsoft Online Assessment questions

  • Maximum Score with Prime JumpsOA · Seen Dec 2026
  • Minimum Non-Adjacent Selection CapabilityOA · Seen Dec 2026
  • Authentication SystemOA · Seen Nov 2026
  • Maximum String OperationsOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Longest Palindromic SubsequenceAXQ Capital · OA
  • Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
  • Longest Subsequence That Is a SubstringBooking.com · OA
  • Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
  • Longest String ChainVisa · OAVisa interview questions
  • Minimum-Cost Digit String DecodingSquadStack.ai · OA
  • Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
  • Substrings Without a Target SubsequencePhonePe · OAPhonePe interview questions
  • Minimum Edit-Distance String for Each QueryTarget · OA
  • Longest Subsequence That Is a SubstringWells Fargo · OAWells Fargo interview questions

Interview reports that mention this question

  • Microsoft OA Questions, October 2026: 4 Experiences

Microsoft interview experiences

  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int getMinimumOperationCount(String s) {
      // Write your code here.
    }
}
Checking account…