Find Streams with All Keywords
Problem statement
Each string in streams lists the keywords of one stream, separated by |. Find the streams that contain every requested keyword from keywords.
Match whole tokens exactly and case-sensitively. Token order does not matter. Repeated tokens in a stream and repeated requested keywords do not change membership. An empty stream contains no keywords. If no keywords are requested, every stream matches.
Return the zero-based indices of matching streams in increasing order. Equal stream strings at different indices represent different streams and keep their separate indices.
Function
mutualKeywordStreams(streams: String[], keywords: String[]) → int[]Examples
Example 1
streams = ["red|blue","blue|green","red|green|blue",""]keywords = ["red","blue"]return = [0,2]Streams 0 and 2 contain both complete tokens. Stream 1 lacks red, and stream 3 is empty.
Example 2
streams = ["dog|datadog","datadog","dog|dog"]keywords = ["dog","dog"]return = [0,2]Requesting dog twice still asks for membership once. Stream 1 contains only datadog, which is a different whole token.
Example 3
streams = ["","a","a"]keywords = []return = [0,1,2]There are no requested keywords, so all three streams match. The two equal strings remain separate streams.
Constraints
0 <= streams.length <= 2000 <= streams[i].length <= 1000- The sum of all stream string lengths is at most
20000. 0 <= keywords.length <= 100- Each keyword has between
1and30characters. - A nonempty stream consists of nonempty tokens separated by a single
|. Each token has between1and30characters. - Tokens and keywords use only ASCII letters, digits, underscores and hyphens. Matching is case-sensitive.