Yahoo Interview Question
Software Engineer / DevelopersCountry: United States
I would use Max heap data structure key for this data structure would be Balance of the Person
So when max balance is query is requested you will get at O(1). But when the persons balances changes based on the heap DS it will chnage its position in the tree which will be O(lgn)..
So building heap will be O(n)..I would represent class:
class Person{
String name;
String location;
float balance;
int day;
float credit(float amount);
boolean debit(float amount);
int getDay();
String getName();
String getLocation();
}
My solution is to use the stack based incremental algorithm. Can anyone provide me the object oriented design.!!
- vgeek August 10, 2013