Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
import java.util.*;
public class Stock {
public static void inStock(int productId){
int id = productId;
HashMap<Integer,Integer> stock = new HashMap<Integer, Integer>();
stock.put(101,5);
stock.put(102,6);
stock.put(103,7);
stock.put(104,8);
stock.put(105,9);
int value = stock.get(id);
if(value==0){
System.out.println(" stock of the product is null");
}
else if( value>0 && value<25) {
System.out.println(" stock of the product going to finish but above 0 and less than 25");
}
else {
System.out.println(" we have a sufficient");
}
}
public static void main(String args[]){
inStock(102);
}
}
Store user and product withslist information in table or data structure. When new stock comes in, do a join on the product id and get the list of customers with the corresponding product wish list and send a notification to them..
just another thought, is this simple, or there is something underthe hood for the problem
here we have a class Store which having list of product and its availability if any customer want any product it is there give him other wise register him for notification for particular product notification list when item is added notify all customer who is available in notification list and remove customer from that notification list."observer pattern"
here we have a class Store which having list of product and its availability if any customer want any product it is there give him other wise register him for notification for particular product notification list when item is added notify all customer who is available in notification list and remove customer from that notification list."observer pattern"
We can utilize 4 main classes:
class User {
String name;
String email;
}
class Product {
String name;
int id;
int amount;
double price;
}
class Store {
ArrayList<Product> inStock;
ArrayList<Product> outStock;
void add(Product) {...} //adds new product to inStock
void remove(Product) {...} //removes product from inStock and outStock
void update(Product) {...} //updates the product information such as
//price/amount and sends notification when amount
//change
}
class NotificationMgr {
Hashmap<int, LinkedList<User>> waitingList;
void register(User, Products[]); //user registers for notifications
void unregister(User, Products[]); //user deregisters for notifications
/*
Use the Observer design pattern to receive the notifications when a product
is moved from the outStock to inStock and send the notification to all registered
users
*/
}
1. when a product is added to system it would generate an event.
- raj May 22, 20122. Customer notification module will register and receive this event.
3. Customer wishlist table will list of customer id with product id they wish for.
4. The event processing will look for customer list for the product id, event is generated for.
5. It would notify those customers.
6. and remove them from the wishlist table.