Amazon Interview Question
SDE1sCountry: United States
Interview Type: In-Person
correct......
becz we have N scientist and k black hole and one scientist can make query at most k black hole..
Absolutely correct. As the number of queries will be much more than number of black holes, so the composition of queries in black hole makes sense.
Absolutely correct. As the number of queries will be much more than number of black holes, so the composition of queries in black hole makes sense.
Absolutely correct. As the number of queries will be much more than number of black holes, so the composition of queries in black hole makes sense.
It's more like a bidirection many-to-many relationship. Hole and Scientist class should have array of the other type for reference. That means you need to have some sort of manager class to maintain the relationship
// Many-To-Many bidirection
class Hole {
private id,
private temperature,
private radius,
private size,
// some getters
private List<Scientist>,
public addScientist(Scientist)
}
class Scientist {
private id, // or name, whatever
private List<Hole> holes
public query(holeId) // this calls the QueryManager
}
class QueryManager {
private Holes[] // all hole objects
public Query(int holeId, scientist) // this should find the hole, add the scientist to the array in the hole. return the hole object.
}
How about a HashMap where scientist is key and there is a linked list of black_holes for the value if the scientist can query multiple black holes.
And the black_hole can it self contain some information about its identity and a linked list of queries made:
- deepanshu February 03, 2015