FastPrepFind Streams with All Keywords
Problems/Find Streams with All Keywords

Find Streams with All Keywords

Datadog logoDatadog● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand report describes stream strings with keywords separated by | and asks for the mutual streams for a keyword array. This practice version defines all-keyword membership, whole-token case-sensitive matching, duplicate and empty-input rules, index output and bounds. The core task matches the report at about 85%.

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 <= 200
  • 0 <= streams[i].length <= 1000
  • The sum of all stream string lengths is at most 20000.
  • 0 <= keywords.length <= 100
  • Each keyword has between 1 and 30 characters.
  • A nonempty stream consists of nonempty tokens separated by a single |. Each token has between 1 and 30 characters.
  • Tokens and keywords use only ASCII letters, digits, underscores and hyphens. Matching is case-sensitive.

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public int[] mutualKeywordStreams(String[] streams, String[] keywords) {
    // Write your code here.
}
Checking account…