FastPrepUnique Users Within Each IP Address

Unique Users Within Each IP Address

Roblox logoRoblox● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

You are given parallel arrays ips and names. Each position describes a username seen at that IP address. A user is unique within an IP if its name is not a prefix of another, strictly longer name at the same IP.

For this exercise, assume exact duplicate (IP, name) pairs describe the same user. Equal names do not exclude one another, and comparisons are case-sensitive. A name at a different IP cannot exclude this user.

Return one [IP, name] row for every surviving distinct pair, in the order its first occurrence appears in the input. If a name is a prefix of a longer name at its IP, omit all occurrences of that pair. Empty inputs return an empty array. Treat IP labels as opaque identifiers; address parsing is unnecessary.

Function

uniqueIpUsers(ips: String[], names: String[]) → String[][]

Examples

Example 1

ips = ["a","a","b","a"]names = ["ann","anna","ann","bob"]return = [["a","anna"],["b","ann"],["a","bob"]]

At IP a, ann prefixes anna. The same name at IP b has no longer competitor and remains.

Example 2

ips = ["x","x","x","y"]names = ["alex","alex","al","al"]return = [["x","alex"],["y","al"]]

Duplicate x/alex appears once. x/al is excluded by alex, while y/al is independent.

Example 3

ips = []names = []return = []

No observations produce no users.

Constraints

  • 0 <= ips.length <= 500 and names.length = ips.length.
  • Each IP label has 1 to 40 characters, using English letters, digits, periods, colons or underscores.
  • Each name has 1 to 40 English letters or digits.

More Roblox problems

See Roblox hiring insights
public String[][] uniqueIpUsers(String[] ips, String[] names) {
    // write your code here
}
ips["a","a","b","a"]
names["ann","anna","ann","bob"]
expected[["a", "anna"], ["b", "ann"], ["a", "bob"]]
Checking account…