I have a string like this:

`A*A**B***A**`

I'm interested in sequences of asterisks that are between two distinct letters, in particular I need to find the length of the shortest such sequence. For the above string the answer is, of course, 2: `A**B`

I can easily solve this problem using a traditional loop, the likes of which I'm accustomed to:

```
const string s = "A*A**B***A**";
string::size_type last_letter=-1, min_seq_len=s.size();
for(int i = 0; i < s.size(); i++) {
    if(last_letter == -1 || s[i] == '*' || s[i] == s[last_letter]) {
        if(s[i] != '*') {
            last_letter = i;
        }
    } else {
        min_seq_len = min(min_seq_len, i-last_letter-1);
        last_letter = i;
    }
}

```

However, is there any way to do this using the C++ [algorithms library](http://en.cppreference.com/w/cpp/algorithm), iterators etc?

I'm asking this question because I've noticed I have trouble learning how to use these facilities to solve algorithmic problems and instead I find writing loops by hand easier. And I'd like to finally learn operating on C++ algorithms, ranges, iterators etc.