Question
In a particular school, each course can only have 1 pre-requisite course. * * These pre-req courses are represented by a map, for example: *
In a particular school, each course can only have 1 pre-requisite course.
*
* These pre-req courses are represented by a map, for example:
*
* {"CS120"="","CS220"="CS120","CS230"="CS220","MA100"="MA102","MA102"="MA100"}
*
* Note that if a course has no pre-req, it is represented by the empty string ""
*
* So in this example, CS120 has no pre-req course.
* CS220 has a pre-req of 120
* CS230 has a pre-req of 220
* MA100 has a pre-req of MA102
* MA102 has a pre-req of MA100
*
* Your job is to write a function that determines how many courses must be taken to take a specific course.
*
* So your function should return 0 for "CS120"
* your function should return 1 for "CS220"
* your function should return 2 for "CS230"
* your function should return -1 for "MA102" or "MA100". They are in a pre-req loop, so it is impossible to take any of the courses.
*
Language is Java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started