n = int(input())
x = input()
def remove(tmp, x):
removed = 0
if len(tmp) >= 2 and tmp[0] == x and tmp[1] == x - 1:
removed += 1
tmp.pop(0)
i = 0
n = len(tmp)
while i < n:
if i == 0:
if len(tmp) >= 2 and tmp[0] == x and tmp[1] == x - 1:
removed += 1
tmp.pop(0)
n -= 1
continue
elif i == n - 1:
if len(tmp) >= 2 and tmp[-1] == x and tmp[-2] == x - 1:
removed += 1
tmp.pop(len(tmp) -1 )
n -= 1
continue
elif tmp[i] == x and (tmp[i + 1] == x - 1 or tmp[i - 1] == x - 1 ):
removed += 1
tmp.pop(i)
i -= 1
n -= 1
continue
i += 1
return removed
def solve (x, n):
out = 0
tmp = [ord(e) for e in x]
chars = list(set(tmp[::]))
chars.sort(reverse=True)
for char in chars:
out += remove(tmp, char)
print(out)
solve(x,n)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
for(int i=122; i>=97;i--)
{
for(int j=0; j<n; j++)
{
if(s[j]==i)
{
if(s[j-1]==i-1 or s[j+1]==char(i-1))
{
s.erase(j,1);
j=-1;
}
}
}
}
// cout<<s<<endl;
cout<<n-s.length()<<endl;
}
17. Letter Combinations of a Phone Number | 5. Longest Palindromic Substring |
3. Longest Substring Without Repeating Characters | 1312. Minimum Insertion Steps to Make a String Palindrome |
1092. Shortest Common Supersequence | 1044. Longest Duplicate Substring |
1032. Stream of Characters | 987. Vertical Order Traversal of a Binary Tree |
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |