Description
Solutions
Get Minimum Operation Count
πŸ‘©β€πŸŽ“ NEW GRAD

A string is beautiful if no two adjacent characters are either

  • the same, for example 'aa'.
  • adjacent in the alphabet, for example 'ef'.
  • The following operations can be performed on a string, s.

  • Choose any index i (0 ≀ i < |s|) and change s[i] to any lowercase English letter.
  • Find the minimum number of operations required to make the string beautiful.

    Function Description

    Complete the function getMinimumOperationCount in the editor below.

    getMinimumOperationCount has the following parameter:

    • s: a string

    Returns

    int: the minimum number of operations required to make s beautiful

    Example 1:

    Input:  s = "abdde"
    Output: 2
    Explanation:

    String s is not beautiful because:

    • 'dd' violates constraint 1, no two adjacent characters are the same.
    • 'ab' and 'de' violate constraint 2, no two adjacent characters are adjacent in the alphabet.

    The string can be converted into a beautiful string after 2 operations. One solution is below:

    • Choose i=1 and change s[i] to 'z', s becomes "azdde".
    • Choose i=3 and change s[i] to 'k', s becomes "azdke" which is beautiful.

    Note: There are many other solutions such as "ardze", "axdke", etc.

    It can be shown that 2 is the minimum number of operations required so return 2.

    Constraints:
      • 2 ≀ |s| ≀ 10^5
      • The string s contains only lowercase English letters.
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: