FastPrepFastPrep
Problem Brief

Video ID Generation (Generic)

NEW GRADOA

TikTok is working to make the process of creating unique video IDs more efficient. A TikTok video ID is represented as a string called idStream of length n, made up of the digits "0" to "9". TikTok also has a list called videoIds, which contains m target video ID strings, each also made up of digits "0" to "9".

For each target video ID in videoIds, find the shortest part of idStream that contains all the characters needed to form any possible arrangement (permutation) of the target string.

You will need to return an array of integers. The number at each position i in the array should be the length of the shortest part of idStream that can include all characters of the ith string in the videoIds. If it is impossible to create the target video ID from idStream, reutrn -1 for that position.

1Example 1

Input
idStream = "064819848398", videoIds = ["088", "364", "07"]
Output
[7, 10, -1]
Explanation
- To construct "088", the first 7 chars of the idStream ("064819848398") contain '0', '8', and '8' :) Therefore, the answer for this target is 7. - To construct '364,' we need to examine the first 10 characters of the idStream ('064819848398') and use the digits '6,' '4,' and '3'. By rearranging these digits to match '364', the answer is 10. (this line of text might be slightly diff from the original explanation, but it should capture the essential meaning and seems very close to the original) - For "07", there is no prefix in the idStream that contains both "0" and "7", so the answer is -1.

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= n <= 105
  • 1 <= m <= 2*104
  • 1 <= sum of the lengths of strings in videoIds <= 5*105
  • All strings consist of characters '0' - '9' only.
  • public int[] videoIDGeneration(String idStream, String[] videoIds) {
      // write your code here
    }
    
    Input

    idStream

    "064819848398"

    videoIds

    ["088", "364", "07"]

    Output

    [7, 10, -1]

    Sign in to submit your solution.