FastPrepGroup Users by Connect or Disconnect

Group Users by Connect or Disconnect

Atlassian logoAtlassian● EasyFULLTIMEPHONE SCREEN

Updated

Problem statement

Given a list users of records [name, action], group the names by action. Each action is Connect or Disconnect.

Return one row for each action that appears in the input, with rows in lexicographic order of action. A row starts with the action, followed by that action's names in input order. Repeated records stay repeated. If users is empty, return an empty list.

For example, records [Alice,Connect], [Bob,Disconnect], and [John,Connect] give the 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"]]

Alice and John have the action Connect, and Bob has Disconnect. Connect sorts before Disconnect, so its row comes first.

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

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

More Atlassian Phone Screen questions

Similar questions at other companies

Atlassian interview experiences

All Atlassian interview questionsSee Atlassian hiring insights
Saved
class Solution {
    public String[][] groupUsers(String[][] users) {
        // Write your code here.
        return new String[0][];
    }
}
Checking account…