FastPrepGroup Users by Connect or Disconnect

Group Users by Connect or Disconnect

Atlassian logoAtlassian● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given a list users of records [name, action], group user names by their action. The two permitted actions are Connect and Disconnect.

Return one row for each action present in the input. A row starts with the action, followed by the names assigned to that action. Order rows lexicographically by action.

For this exercise, assume names within each action group preserve their input order, repeated records remain repeated, and an empty input returns an empty list.

For example, records [Alice,Connect], [Bob,Disconnect], and [John,Connect] produce groups Connect: [Alice,John] and Disconnect: [Bob].

Function

groupUsers(users: String[][]) → String[][]

Examples

Example 1

users = [["Alice","Connect"],["Bob","Disconnect"],["John","Connect"]]return = [["Connect","Alice","John"],["Disconnect","Bob"]]

This preserves the reported action groups.

Example 2

users = [["Lee","Disconnect"],["Lee","Connect"],["Lee","Disconnect"]]return = [["Connect","Lee"],["Disconnect","Lee","Lee"]]

Lee appears once under Connect and twice under Disconnect; occurrences remain in order.

Constraints

  • For this exercise, assume 0 <= users.length <= 500.
  • Every record contains exactly two strings: a nonempty name and one of Connect or Disconnect.
  • For this exercise, assume names contain 1 through 50 ASCII letters, digits, or underscores and are case-sensitive.

More Atlassian problems

See Atlassian hiring insights
public String[][] groupUsers(String[][] users) {
    // Write your code here.
    return new String[0][];
}
users[["Alice","Connect"],["Bob","Disconnect"],["John","Connect"]]
expected[["Connect", "Alice", "John"], ["Disconnect", "Bob"]]
Checking account…