Official
D - Typing Editorial by en_translator
Maintain a variable to manage how many first characters of \(S\) has been typed, while scanning the characters of \(T\).
Sample code
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
vector<int> a(n);
int j = 0;
for (int i = 0; i < m; i++) {
if (s[j] == t[i]) {
a[j] = i + 1;
j++;
}
}
for (int i = 0; i < n; i++) cout << a[i] << " \n"[i == n - 1];
}
posted:
last update: