A search results page shows a short snippet of each document doc around the query query. The snippet must be a slice of neighboring characters of doc that contains every character of query, including repeats: if query has two as, the snippet needs at least two as.
Write smallestSnippet(doc, query) that returns the shortest such slice. If several slices have the shortest length, return the one that starts first. If no slice works, return "".
Input: doc = "RAZBXCYACBZ", query = "ABC" Output: "ACB"
ACB has A, B, and C and is the shortest such slice.
Input: doc = "a", query = "aa" Output: ""
doc has only one a.
1 <= doc.length, query.length <= 100000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #147 Smallest Snippet With Every Keyword Letter. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.