Remove Prefix Strings
Updated
Problem statement
You are given an array of strings words. Remove words[i] if it is a prefix of any strictly longer string in the array.
Return the strings that remain in their original input order. Equal strings do not remove one another merely because they match; however, every copy of a string is removed if that string is a prefix of some longer word.
Function
removePrefixStrings(words: String[]) → String[]Examples
Example 1
words = ["ab", "abc", "abcd", "bc", "bcd", "bd"]return = ["abcd", "bcd", "bd"]ab and abc prefix longer strings, and bc prefixes bcd, so those three strings are removed.
Example 2
words = ["a", "ab", "abc"]return = ["abc"]a and ab are prefixes of longer strings. Only abc remains.
Example 3
words = ["apple", "banana", "cherry"]return = ["apple", "banana", "cherry"]No word is a prefix of a longer word in the input.
Example 4
words = ["a", "a", "ab"]return = ["ab"]Both copies of a are prefixes of the longer word ab, so both are removed.
Constraints
1 <= words.length <= 100001 <= words[i].length <= 100words[i]contains lowercase English letters.- Preserve the original order of the strings that remain.
- Only a strictly longer string can cause removal.
More Roblox Phone Screen questions
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Rate Limit by Multiple Request FieldsPHONE SCREEN · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Time-Aware Search AutocompletePHONE SCREEN · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 2026
Similar questions at other companies
- Every Distinct Substring in OrderAdobe · PHONE SCREENAdobe interview questions
- Shell Path AutocompleteFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Top K Query SuggestionsMicrosoft · PHONE SCREENMicrosoft interview questions
- Find the Words for Each PrefixDocuSign · PHONE SCREENDocuSign interview questions
- Find All Word Occurrences in TextSentry · PHONE SCREENSentry interview questions
- Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
- Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
- Search Suggestions with a Prefix TreeCitadel · ONSITE INTERVIEWCitadel interview questions
- Highlight and Rank Overlapping CitationsHarvey · ONSITE INTERVIEWHarvey interview questions
- Suggested ProductsSquarepoint Capital · OASquarepoint Capital interview questions
Roblox interview experiences
- Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
- Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
- Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
- Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
- Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)
- Roblox New Grad Coding Rounds: 23 Experiences (Part 2 of 7)