Hired.com Interview Questions
- 0of 0 votes
AnswersYou are given a limit buffer class that has two parameters - window in milliseconds and a threshold of the buffer. This means that the buffer can hold threshold amount of items within window in milliseconds.
There is a stream of data that consists of an event name:
call_backup, retrieve_data, call_backup, log_info, backup_log...
which is added onto the LimitBuffer. Write a logic that calls alert(..) when the buffer exceeds the threshold for a given window.
- dmachop June 11, 2016 in United Statesclass LimitBuffer { public LimitBuffer(long windowMs, int threshold) { } private void alert(String eventName) { } public void addEvent(String eventName) { } } /*class LimitBufferTester { LimitBuffer buffer = new LimitBuffer(2000, 30); while(true) { String randomStr = null; buffer.addEvent(randomStr); } }*/
| Report Duplicate | Flag | PURGE
Hired.com Java Developer - 1of 1 vote
AnswersYou have just earned $500 voucher to spend at any restaurant. However,
since you are a programmer and a foodie you want to maximize how you
allocate your money.
Attached is CSV that has a list of:
-Beverages
-Appetizers
-Entrees
-Desserts
-Restaurants
The CSV file looks something like
Beverage Name,Beverage Cost,Beverage Value,Appetizer Name,Appetizer Cost,Appetizer Value,Entrée Name,Entrée Cost,Entrée Value,Desert Name,Desert Cost,Desert Value,Restaurant Name,Restaurant Drink Cost,Restaurant Value
7up, $92.00 ,32,Fresh Rolls, $82.00 ,30,Fried Rice, $78.00 ,29,Vanilla Ice Cream, $76.00 ,13,Applebee's, $43.00 ,19
Sprite, $89.00 ,24,Spring Rolls, $54.00 ,18,PB & J, $49.00 ,29,chocolate cake, $50.00 ,25,Arby's, $26.00 ,5
Next to each item there is a cost and a perceived value.
Your job is to construct a meal under your budget of $500 that includes:
1 Beverage
3 Appetizers
2 Entrees
1 Dessert
1 Flex Option (This can be an Appetizer, Entree, or Desert)
1 Restaurant
1. Please list the 25 Combinations with the highest perceived value
given your budget
2. Please list the 25 Combinations with the lowest perceived value
given your budget.
Make sure your program assumes that the number of items in each
category is N
The problem I am having is using the knapsack algorithm in this case, especially with item constraints. The problem seems to be poorly written.public static void main(String[] args) throws IOException { File file = new File("Menu.csv"); List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); List<Beverage> beverages = new ArrayList<>(); List<Appetizer> appetizers = new ArrayList<>(); List<Entree> entrees = new ArrayList<>(); List<Dessert> desserts = new ArrayList<>(); List<RestaurantDrink> restaurantDrinks = new ArrayList<>(); boolean firstLine = true; for (String line : lines) { if (firstLine) { firstLine = false; continue; //don't care about first line } String[] array = line.split(","); int j = 0; Beverage b = new Beverage(); Appetizer app = new Appetizer(); Entree e = new Entree(); Dessert d = new Dessert(); RestaurantDrink rd = new RestaurantDrink(); for (String a : array) { switch (j) { case 0: if (!a.equals("")) //nothing { b.name = a; } break; case 1: if (!a.equals("")) //nothing { b.cost = Double.parseDouble(a.replace("$", "")); } break; case 2: if (!a.equals("")) //nothing { b.perceivedValue = Integer.parseInt(a); beverages.add(b); } break; case 3: app.name = a; break; case 4: app.cost = Double.parseDouble(a.replace("$", "")); break; case 5: app.perceivedValue = Integer.parseInt(a); appetizers.add(app); break; case 6: e.name = a; break; case 7: e.cost = Double.parseDouble(a.replace("$", "")); break; case 8: e.perceivedValue = Integer.parseInt(a); entrees.add(e); break; case 9: d.name = a; break; case 10: if (a.equals("")) //free dessert { d.cost = 0.00; } else { d.cost = Double.parseDouble(a.replace("$", "")); } break; case 11: if (a.equals("")) //free dessert { d.perceivedValue = 0; } else { d.perceivedValue = Integer.parseInt(a); } desserts.add(d); break; case 12: rd.name = a; break; case 13: if (a.equals("")) //free restaurant drink { rd.cost = 0.00; } else { rd.cost = Double.parseDouble(a.replace("$", "")); } break; case 14: if (a.equals("")) //free dessert { rd.perceivedValue = 0; } else { rd.perceivedValue = Integer.parseInt(a); } restaurantDrinks.add(rd); break; } j++; } j = 0; } }
is all I got. I'm just having trouble with the knapsack portion.
- Johnb December 03, 2014 in United States| Report Duplicate | Flag | PURGE
Hired.com None None Algorithm