Minimum Stickers to Form a Target String
Updated
Problem statement
Given sticker strings and a target string, return the minimum number of stickers needed to form the target.
- Each sticker type may be used any number of times.
- Each occurrence of a letter on a chosen sticker may cover at most one equal, still-uncovered target position.
- Letters on a sticker may be used in any order, and unused letters may be discarded.
- Return
-1when the target cannot be formed.
Function
minStickers(stickers: String[], target: String) → intExamples
Example 1
stickers = ["with","example","science"]target = "thehat"return = 3Two copies of with and one copy of example can supply all letters of thehat, and two stickers cannot cover every required occurrence.
Example 2
stickers = ["notice","possible"]target = "basicbasic"return = -1No sticker contains the letter a, so the target is impossible.
Constraints
1 <= stickers.length <= 50.1 <= stickers[i].length <= 20.0 <= target.length <= 15.- Every sticker and the target contain only lowercase English letters.
More ByteDance Onsite Interview questions
- Search a Row- and Column-Sorted MatrixONSITE INTERVIEW · Seen Nov 2026
- Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Implement Multi-Head AttentionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dynamic Median with Additions and DeletionsONSITE INTERVIEW · Seen Oct 2026
- Serialize and Deserialize a String Key-Value StoreONSITE INTERVIEW · Seen Oct 2026
- Binary Tree Maximum Path SumONSITE INTERVIEW · Seen Oct 2026
- Merge Overlapping IntervalsONSITE INTERVIEW · Seen Oct 2026
- Tic-Tac-Toe Move WinnersONSITE INTERVIEW · Seen Oct 2026
- Kth Largest Element without a HeapONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Optimal Account BalancingAmazon · ONSITE INTERVIEW
- Minimum Insertion Steps to Make a String PalindromeInfosys · ONSITE INTERVIEWInfosys interview questions
- Wildcard MatchingTripjack · ONSITE INTERVIEWTripjack interview questions
- Interleaving StringsCARS24 · ONSITE INTERVIEW
- Count and Score Distinct Hat AssignmentsRoblox · ONSITE INTERVIEWRoblox interview questions
- Count Magical Adjacent Substring TripletsGoogle · ONSITE INTERVIEWGoogle interview questions
- Maximum Currency Conversion Along a Simple PathRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Hybrid Run-Length and Bit-Packing EncoderDatabricks · ONSITE INTERVIEWDatabricks interview questions
- Maximize Valid TrainsBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
- Longest Valid ParenthesesMathWorks · ONSITE INTERVIEWMathWorks interview questions
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience