#C151. Tag-Based User Sorting

    ID: 44723 Type: Default 1000ms 256MiB

Tag-Based User Sorting

Tag-Based User Sorting

You are given a list of users in JSON format via standard input. Each user is a JSON object with four fields:

  • id: a string representing the user id,
  • username: the user name as a string,
  • tags: an array of strings representing the interests or skills of the user, and
  • last_active: a string representing the date and time of last activity in ISO format.
Your task is to build a mapping from each tag to the list of usernames that have that tag. For every tag, the list of usernames must be sorted in lexicographical (alphabetical) order. Output the mapping as a JSON object.

There are no specific constraints regarding the number of users or tags.

inputFormat

The input consists of a single line containing a JSON array. Each element in the array is a JSON object with the following keys:

  • id: a string
  • username: a string
  • tags: an array of strings
  • last_active: a string in ISO date-time format
You can assume the input is well-formed.

outputFormat

Output a JSON object mapping each tag to a sorted (in lexicographical order) array of usernames associated with that tag. The output should be printed to standard output.## sample

[
  {"id": "1", "username": "alice", "tags": ["python", "data-science"], "last_active": "2023-09-15T13:45:00"},
  {"id": "2", "username": "bob", "tags": ["java", "data-science", "cloud"], "last_active": "2023-09-10T12:30:00"},
  {"id": "3", "username": "charlie", "tags": ["python", "java", "cloud"], "last_active": "2023-09-12T08:20:00"}
]
{"python": ["alice", "charlie"], "data-science": ["alice", "bob"], "java": ["bob", "charlie"], "cloud": ["bob", "charlie"]}