Minimum Changes for a Beautiful String
Updated
Problem statement
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) → intExamples
Example 1
s = "bddje"return = 1Changing the second d to f gives bdfje, whose adjacent differences are all greater than one.
Example 2
s = "acaz"return = 0Every adjacent alphabet-index difference is already at least two.
Constraints
1 <= s.length <= 100000.scontains 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