SnowflakeOA #34
String Search (Also for Core/Database Engineering)
Estimated MediumJudge-ready
Topics (AI-labelled)Binary SearchTwo Pointers
Delete characters of source one by one following order, a permutation of 1-based original indices; original indices are not renumbered after deletions. target is initially guaranteed to be a subsequence of source. Find the maximum number of leading deletions that can be performed consecutively while target remains a subsequence.
Input
The first two lines contain source and target (words without whitespace characters), and the last line contains a 1-based permutation of indices whose length equals the length of source. 1≤|source|≤100000, 1≤|target|≤|source|. Letter case is not arbitrarily restricted, and comparisons are case-sensitive.
Output
Output the single integer required by the problem.
Example 1
Input:
abbabaa
bb
7 1 2 5 4 3 6
Output:
3
Example 2
Input:
hkbdi
kd
1 4 2 3 5
Output:
1
Example 3
Input:
AaA
A
1 3 2
Output:
1
Example notes
The answers to the three public examples are, in order: 3; 1; 1. The examples were rechecked by independent enumeration, state search, or direct simulation.
Editorial
Loading solution…