Comment Word and Substring Search
Updated
Problem statement
You are given parallel arrays commentIds and comments. Each comment has a unique integer ID and a text string. Return the IDs of comments matching the search word.
- In
WORDmode, the query must equal a complete space-delimited word. - In
SUBSTRINGmode, the query may occur inside a longer word.
Text and queries use lowercase English letters; text may also contain spaces. A word is a nonempty group of consecutive letters, bounded by spaces or the start or end of the text. Return each matching ID once, in the same order as the input comments. The collection is fixed for this call.
Function
searchComments(commentIds: int[], comments: String[], word: String, mode: String) → int[]Examples
Example 1
commentIds = [41,7,20]comments = ["red bird","bluebird red","blue bird"]word = "bird"mode = "WORD"return = [41,20]Only complete tokens match; bluebird does not.
Example 2
commentIds = [41,7,20]comments = ["red bird","bluebird red","blue bird"]word = "bird"mode = "SUBSTRING"return = [41,7,20]The substring follow-up also matches bluebird.
Example 3
commentIds = [8,3]comments = ["green green","blue"]word = "green"mode = "WORD"return = [8]Repeated occurrences in one comment still produce one ID.
Constraints
0 <= commentIds.length = comments.length <= 1000.- Comment IDs are unique integers between
0and10^9. - The total number of text characters is at most
10^5. 1 <= word.length <= 100.- Texts contain lowercase English letters and spaces; the query contains lowercase English letters only.
modeisWORDorSUBSTRING.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
- Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
- Group AnagramsWorkday · PHONE SCREEN
- Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions
- Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW