Purpose
Returns the minimum index where character c appears at or after the i-th character of the string. Returns the string length if it doesn’t exist.
Time Complexity
Usage
auto res = nextCharIndex(s);s is a std::string. Use res[i][j] to get the index where character c appears at or after the i-th character (inclusive).
Implementation
vector<vector<int>> nextCharIndex(string &_s) { vector m(_s.size() + 1, vector<int>(26)); for (int i = 0; i < 26; i++) m[_s.size()][i] = _s.size(); for (int i = _s.size() - 1; i >= 0; i--) for (int j = 0; j < 26; j++) if (_s[i] - 'a' == j) m[i][j] = i; else m[i][j] = m[i + 1][j]; return m;}