编辑代码

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
  const strA = await readline();
  const strB = await readline();
  // idxs记录b中每个字符的下标
  const idxs = {};
  for (let i = 0; i < strB.length; i++) {
    idxs[strB[i]] = i;
  }
  // count记录扫描过程中出现的B中字符串的数量:
  // b=bac:当a中出现b或c时,先判断前面的元素是否等于当前字符,如果等于就不能++
  const count = new Array(strB.length).fill(0);
  for (let c of strA) {
    const idx = idxs[c];
    if (idx !== undefined && (idx === 0 || count[idx] < count[idx - 1]))
      count[idx]++;
  }
  console.log(count[count.length - 1]);
})();