Write a method called sectionListsToMap
that, given a List
of String
s, parses it into a
Map<String, MutableSet<String>>
as follows.
Each String
in the passed list contains a comma-separated list of names of people in a discussion section.
The first name is the section leader, and the rest are students.
Your map should map each section leader to the set of students in their section.
No section leader or student will appear twice in the data set.
For example, given the String
s "challen,student1", "ruisong4,student2, student3" and "friendly,student4, student5",
your map would have keys "challen", "ruisong4", and "friendly".
"challen" would map to a set containing "student1", "ruisong4" would map to a set containing "student2" and
"student3", and so on.
A few hints for approaching this problem.
First, consider how to use .split
and .trim
appropriately to parse the input String
.
You should get this part to work before proceeding.
Then consider when you need to create the map and each set, and how to populate them.
You should not need import
statements to solve this problem.
Rather, create your maps and sets using mutableMapOf()
and mutableSetOf()
where appropriate.
Stuck? You may find these lessons helpful: