I have the following scenario:
In the details variable, I need to remove a course from the mutable set of courses, for each student based on a condition.

If I remove as I have done below, I get concurrent modification exception, because I am modifying the variable while iterating through it.

How can I iterate the map in reverse so that it doesn't throw the deadlock, or is there a better way to handle this scenario ?

```kotlin
val details = MutableMap<Student, MutableSet<CourseDetail>>

details?.forEach { student, courses ->
    courses?.forEach { course ->
       if (b?.contains(course) == false) {
           details[student]?.remove(course)
    }
  }
}

```