String Search (Also for Core/Database Engineering)
Learn this problemProblem statement
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:
Function
getMaximumRemovals(order: int[], source: String, target: String) → int
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 🌸࿐ ࿔*:・゚
Examples
Example 1
order = [7, 1, 2, 5, 4, 3, 6]source = "abbabaa"target = "bb"return = 3Example 2
order = [1, 4, 2, 3, 5]source = "hkbdi"target = "kd"return = 1Constraints
More Snowflake problems
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerSeen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringSeen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026
- Efficient DeploymentsOA · Seen Jun 2026
- Character Frequencies Across Nested String ListsPHONE SCREEN · Seen Jun 2026
- Character Frequencies Across StringsPHONE SCREEN · Seen Jun 2026