Amazon Interview Question
SDE-2sTeam: Online Fraud Prevention
Country: United States
Interview Type: Phone Interview
Every user would be given default space during signup , and on every referral he would be given bonus space.The information related to bonus space can be stored in a map.
This map contains ReferredUser and bonus space .
To get total space of a user we should add default space and total free space acquired by referral.
class user
{
Space space;
....
....
}
Class Space
{
int initialSpace; //the default space that the user gets on signup
Map ReferredUsers<User,int>;//Map of referred user and free space aquired as referral bonus
TotalSpace()
{
for(each referred_user in ReferredUserList)
tempspace = tempspace + referred_user.second ; //get the free space from map
return tempspace + initialSpace;
}
....
First we have the user - this is for an existing user
class User {
//Basic information
int id;
String name;
String email;
/* total space -- need to add more information about the account
but this is enough for this question (available, max, etc)
*/
int space;
int add_space(int amount) {...}
}
Second we need something to represent an invitation
class Invite {
String email; //email of the person being invited
int id; //id of the user who invited him
Date sent_date; //These 2 will allow the system to
boolean status; //track the invite status and send
//automatic reminders
}
Third there needs to be a system to manage all of this
class Dropbox {
map<int, User> users; //all the users
ArrayList<Invite> invites; //all invitations sent
//sends an invite to the email inputed by the user
//and adds a new Invite to the invites ArrayList
void sendInvite(User from, String to) {...}
//When the invited party accepts the invitation
//this function is triggered and:
//1. Creates a new User and adds to users.
//2. Finds the user that invited him from the invites list
// (according to email and id) and calls add_space
void accept(String email) {...}
}
I am just curious... what answer did u give and what kind of design patterns did u use ?
- king July 11, 2013