Remove Punctuation and Stop Words
Updated
Problem statement
Clean text using the supplied punctuation characters and stopWords list. Return the cleaned string.
For this exercise, assume cleaning happens in this order: first delete every character that appears in punctuation, without inserting spaces. Then split the remaining text at spaces and remove each whole token that exactly matches a stop word. Matching is case-sensitive. A stop word does not remove part of a longer token.
Return the remaining tokens in their original order, separated by one space with no leading or trailing spaces. Return an empty string when no tokens remain. Characters absent from punctuation stay in their tokens.
Function
cleanText(text: String, punctuation: String, stopWords: String[]) → StringExamples
Example 1
text = "Hello, and world!"punctuation = ",!"stopWords = ["and"]return = "Hello world"Deleting the comma and exclamation mark gives Hello and world. Removing the whole stop word and leaves Hello world.
Example 2
text = "red-blue red blue"punctuation = "-"stopWords = ["blue"]return = "redblue red"Deleting the hyphen joins the first token into redblue. Only the final whole token blue is removed; the letters blue inside redblue remain.
Constraints
- For this exercise, assume
0 <= text.length <= 10000. - Text contains only printable ASCII characters, with codes 32 through 126.
0 <= punctuation.length <= 100. Its characters are printable ASCII symbols other than letters, digits, and spaces. Repeats are allowed.0 <= stopWords.length <= 100. Each stop word contains 1 to 30 ASCII letters. Repeats are allowed.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
- Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
- Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Branch with the Most FilesCapital One · OACapital One interview questions