Graph academy: Getting DISTINCT values from a map projection

I'm doing the exercises from the Intermediate Cypher Queries- Pipelining queries and in the Unique Genres one I was asked to get something like a set of values from a specific dictionary "Key" (at least I would see it like this if I was working on Python).
The Query from the solution is the following:

MATCH (n:Movie)
WHERE n.imdbRating IS NOT NULL AND n.poster IS NOT NULL
WITH n {
.title,
.imdbRating,
actors: [ (n)<-[:ACTED_IN]-(p) | p { tmdbId:p.imdbId, .name } ],
genres: [ (n)-[:IN_GENRE]->(g) | g {.name}]
}
ORDER BY n.imdbRating DESC
LIMIT 4
RETURN collect(n)

I understand the questions expects me to "manually" keep track of the Genres result and count them in order to answer the exercise.

Do you know a way to make something like

RETURN apoc.coll.toSet[collect(n.genres[i].name) for i range(0, size(collect(n))) ]?

My idea was to iterate over all elements in my collection(n), getting the value (a list in this case) from the "genres" key, making a set of these, then make another collection, and just then applying one last transformation to this list in order to convert its entries to a set.

Sorry, I am not following your final requirement, so I will give you an example that may help

Let’s say you want to get the unique genre names from your collect(n) result. We will use the app.coll.toSet function to remove duplicate names.

apoc.coll.toSet(reduce(s=[], i in collect(n) | s+[j in i.genre | j.name]))

We could do the same with cypher removing duplicate names.

reduce(s=[], i in collect(n) | s+[j in i.genre where not j.name in s | j.name])