So, I came across this question that is apparently being asked in pre-screen tests this year and thought to share it with the community. I have written a solution in python3 and have posted it below. Better solutions - with regards to time complexity in java are welcome and will be greatly appreciated (especially by me since I am not big with Java and would very much like to see a implementation for it). It is a data structures question that has 3 objectives.
1. First, need to come up with a data structure to hold the following type of data.
2. Write an algorithm to check if the relations below are cyclic in nature.
3. Find the issuer with max rating
Is Python really an object‑oriented language? If I were writing that in Java®, I would start by creating an object to encapsulate all those data. Java® also provides a better way to order the ratings from AAA to C. Why have you declared the same mappings twice (lines 25 and 36)?
Thank you so much for replying guys!! I am just starting Java so cannot really code this up in java right away! But I would categorize this as a difficult question, took me over an hour to write the python code.
I will greatly appreciate if someone can code this up in Java so I can get a feel of how to go about. It is a bit of an undertaking but I will really really appreciate.