Loading Similar Posts
Sequential String
vector<int> solution(const string &s, const vector<string> &q) {
const int n = s.length(), m = q.size();
vector<vector<int>> have(10);
for (int i = 0; i < n; ++i) {
have[s[i] - '0'].push_back(i + 1);
}
vector<int> r(m);
for (int i = 0; i < m; ++i) {
vector<int> num(10);
for (char c : q[i]) {
const int x = c - '0';
if (++num[x] > have[x].size()) {
r[i] = -1;
break;
}
r[i] = max(r[i], have[x][num[x] - 1]);
}
// cout << r[i] << endl;
}
return r;
}
int main() {
solution("111222333444", {"121", "3", "12345", "11234"});
}
Task Scheduling