Detect a Keyword Substring
Updated
Problem 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.
More Amazon Onsite Interview questions
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dungeon GameONSITE INTERVIEW · Seen Nov 2026
- Integer BreakONSITE INTERVIEW · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Valid ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
- Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
- Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
- Implement tail -nConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Valid ParenthesesEPAM · ONSITE INTERVIEWEPAM interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions