String Search (Also for Core/Database Engineering)
A search engine is being trained on an algorithm for searching similar words. Given two words, source and target, characters are removed from the string source one by one following the sequence of indices defined by the permutation order[]. More formally, order[] is a permutation of length n (length of string source), and in the ith step of the removal, the character at index order[i] is removed from the string source, while keeping the other characters at their original indices.
The string target is said to be searchable in the string source, if it appears as a subsequence in the source string. Find the maximum number of characters which can be removed by following the order defined by the permutation order[], such that the string target remains searchable in the string source.
Note:
Complete the function getMaximumRemovals in the editor.
getMaximumRemovals has the following parameters:
int order[order_size]: the order in which characters are removed from string sourcestring source: the initial stringstring target: the desired subsequenceReturns
int: the maximum possible removals such that target exists as a subsequence of source
ππ, Credit to robot πΈΰΏ ΰΏ*:ο½₯οΎ
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.