1. for each character, find the length of the longest continous substring that ends with that character
  2. for each character the number of continous substrings that end in that character = length of the longest continous substring that ends in that character ( as obtained in step 1 )
explanation

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
function findSubstringInWraproundString(s: string): number {
    let curStreak = -1,
        lenMap = new Array(26).fill(0);

    for ( let i=0; i < s.length; i++ ) {
        if ( i > 0 && isContinous( s[i-1], s[i] ) ) curStreak++;
        else curStreak = 1;

        lenMap[ CODE(s[i]) ] = Math.max( lenMap[ CODE( s[i] ) ], curStreak );
    }

    return lenMap.reduce( (sum, curLen) => sum += curLen, 0 );
};

function isContinous( c1: string, c2: string ) {
    return ( CODE(c2) - CODE(c1) + 26 ) % 26 == 1;
}

function CODE( c: string ) {
    return c.charCodeAt(0) - 'a'.charCodeAt(0);
}