Expedia SDE3 first technical interview
261
May 15, 2025
Found these questions on my technical phone screen interview
- Simple backtracking problem to get all possible combinations
- The question was similar to this
Here is a sample questions where we get a stream of objects [B1, 6, 200],[B2, 10, 160],[B3, 130, 200][B4, 12, 400] and a time of 60 seconds we have to optimize the amount that we can have in 60 seconds. The three parameter in the list are [id, time, amount]. Can we solve this using the classic knapsack recursive approach if there is no time sequence in the events that we have to worry about as in B1 can come after B3 and B4 can come before B2
Here was my approach to solve it using the classic 0/1 knapsack approach
public class MaximizeEventAmount {
static class Item {
String id;
int time;
int amount;
public Item(String id, int time, int amount) {
this.id = id;
this.time = time;
this.amount = amount;
}
}
public static void main(String[] args) {
Item[] items = {
new Item("B1", 6, 200),
new Item("B2", 10, 160),
new Item("B3", 130, 200),
new Item("B4", 12, 400)
};
int totalTime = 60;
int maxAmount = knapsack(items, totalTime, 0);
System.out.println("Max amount: " + maxAmount);
}
static int knapsack(Item[] items, int remainingTime, int index) {
if (index == items.length || remainingTime == 0) {
return 0;
}
if (items[index].time > remainingTime) {
return knapsack(items, remainingTime, index + 1);
}
int take = items[index].amount + knapsack(items, remainingTime - items[index].time, index + 1);
int skip = knapsack(items, remainingTime, index + 1);
return Math.max(take, skip);
}
}Let me know if there is a better way to solve this problem.
Comments (2)


