Problem · String
Detect a Keyword Substring
Learn this problemProblem statement
Given a string text and an array of nonempty keywords, return true when at least one keyword occurs as a contiguous substring of text.
For this exercise, assume matching is case-sensitive and literal. An empty keyword array produces false.
Function
containsKeyword(text: String, keywords: String[]) → booleanExamples
Example 1
text = "distributed systems interview"keywords = ["system","database"]return = trueThe keyword system occurs inside systems.
Example 2
text = "Cloud"keywords = ["cloud","database"]return = falseMatching is case-sensitive, so cloud does not match Cloud.
Constraints
0 <= text.length <= 10^50 <= keywords.length <= 10^41 <= keywords[i].length <= 10^4- The total keyword length is at most
10^5.