# 17. 求满足条件的最长子串的长度

17

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
rl.on('line', function(str)) {
    let maxLen = -1;
    let hasLetter = false;
    let l=0, r=0;
    let letterIdx = [];
    while(r < str.length) {
        let c = str[r];
        if (c.match(/[a-zA-Z]/)) {
            hasLetter = true;
            letterIdx.push(r);
            if (letterIdx.length > 1) {
                l = letterIdx.shift() + 1;
            }
            if (l === r) {
                r++;
                continue;
            }
            maxLen = Math.max(maxLen, r - l + 1);
            r++;
        }
        if (!hasLetter) {
            console.log(-1);
        } else {
            console.log(maxLen);
        }
    }

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34