Sequential String
Learn this problemProblem statement
A special string of length n consists of characters 0-9 only. Its characters can only be accessed sequentially i.e the first '1' chosen is the leftmost '1' in s. There is an array arr of m strings, also consisting of characters 0-9. Calculate the minimum number of characters needed from s to construct a permutation of each of the strings in arr.
Return an array of integers where the ith element denotes the minimum length of a substring that contains a permutation of the ith string in arr. If a string cannot be constructed, return -1 at that index.
Function
countMinimumCharacters(s: String, arr: String[]) → int[]
Complete the function countMinimumCharacters in the editor below.
countMinimumCharacters has the following parameters:
String s: the special string of lengthnString[] arr: an array of strings
Returns
int[]: an array of integers where each element denotes the minimum length of a substring needed to construct a permutation of the string at that index in arr, or -1 if it cannot be constructed
Examples
Example 1
s = "064819848398"arr = ["088", "364", "07"]return = [7, 10, -1]n=12, s="064819848398", m=3, arr=["088", "364", "07"]:
[7, 10, -1]. Note that only bolded characters are used to construct the strings.Constraints
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