FastPrepVideo ID Generation (Generic)
Problems/Video ID Generation (Generic)

Video ID Generation (Generic)

TikTok logoTikTok● MediumNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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.

Function

videoIDGeneration(idStream: String, videoIds: String[]) → int[]

Examples

Example 1

idStream = "064819848398"videoIds = ["088", "364", "07"]return = [7, 10, -1]
  • 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

  • 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.

More TikTok interview questions

  • Minimum Cost of Every K-Capable Model SetOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Oct 2026
  • Next Greater Indices and Maximum GapPHONE SCREEN · Seen Oct 2026
  • Count Subarrays with at Least K Equal-Fruit PairsOA · Seen Oct 2026
  • Shell Command Counts with History ReferencesOA · Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Sep 2026
  • Product Minus Sum of DigitsOA · Seen Aug 2026
  • Count 2x2 Submatrices by Black CellsOA · Seen Aug 2026
  • Find All Local PeaksOA · Seen Aug 2026
  • Count Case-Insensitive TripletsOA · Seen Aug 2026

Similar questions at other companies

  • Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
  • Perfect SubstringAXQ Capital · OA
  • Longest Distinct StringSuperhuman · OASuperhuman interview questions
  • Longest Substring Without Repeating CharactersAkuna Capital · OAAkuna Capital interview questions
  • Perfect SubstringsVisa · OAVisa interview questions
  • Vowel SubstringSnowflake · OASnowflake interview questions
  • Count Distinct Fixed-Length SubstringsAdobe · OAAdobe interview questions
  • Unaligned DedupeRubrik · OARubrik interview questions
  • Get Max OccurrencesIBM · OAIBM interview questions
  • Find P-Matching ScoreAmazon · OA

TikTok interview experiences

  • TikTok AI Infra Intern LLM Round 2: 1 Experience
  • TikTok AI Infra Intern DeepSpeed Round: 1 Experience
  • TikTok AI Infra Intern Kernel Round: 1 Experience
  • TikTok AI Infra Intern Interviews, 3 Rounds: 1 Experience
  • TikTok AI Infra Intern Interview Timeline: 1 Experience
  • TikTok AI Infra Intern Onsite Round 2: 1 Experience
All TikTok interview questionsSee TikTok hiring insights
Saved
class Solution {
    public int[] videoIDGeneration(String idStream, String[] videoIds) {
      // write your code here
    }

}
Checking account…