← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Given an array of strings words, remove every string for which another, strictly shorter string in words is its prefix. Return the remaining strings in their original input order.
Formally, drop words[i] if there exists some words[j] such that words[j].length < words[i].length and words[i].startsWith(words[j]).
`removePrefixStrings(["ab", "abc", "abcd", "bc", "bcd", "bd"]) -> ["ab", "bc", "bd"]
/ delimiter). A sort + linear scan also works and is shorter to write. Both are shown in the reference solution.
This was reported from a Roblox phone screen (September 2025)."abc", "abcd", "bcd" are removed because shorter strings in the array ("ab", "ab", "bc") are prefixes of them. "ab", "bc", "bd" are kept because no shorter string is a prefix.
None of the strings is a prefix of any other, so the array is returned unchanged.