Skip to main content
All Questions

Find the minimum operations to make a string beautiful.

Unlock detailed company stats for this questionUpgrade

A string is beautiful if no two adjacent characters are the same or adjacent in the alphabet. One operation changes any character to any lowercase letter. Return the minimum number of operations to make the string beautiful.

Function: int getMinimumOperationCount(string s). Example: 'bddje' -> 1 (change second d to f). 'a' and 'z' are not consecutive. Expected approach: DP over last letter, O(n * 26^2). Edge cases: length 1 -> 0; 'aa', 'ab', 'yx' must change; 'ac', 'az' are valid.

Format · Microsoft Data Science Intern OA (job 200041778).

Community answers

No answers contributed by the community yet.

Related courses

Course

Data Science Interview Prep

Land your dream data science role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.

Course

SQL Interview Prep Course

Prepare for SQL interviews with lessons on joins, aggregations, and window functions, then practice real SQL interview questions in an interactive editor with expert solutions.