Google Phone Screen Interview Question
Company: Google
Role: unknown
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
I was asked this question in an interview recently, sharing the details:
Given a bag weight W, how to maximize profits given each object has weights assigned (Classic 0-1 knapsack)
Proposed a DP solution.
Follow-up:
- What happen if the weights are fractional ?
- What happens if the profit of each of the item is either 1 or 2?
I gave a solution with time complexities, for both the follow-ups but the interviewer wasn't convinced with my approach and got rejected.
What do you think should the optimal solution be ?
Edit 1
By fractional weights, interviewer meant
1. You are not allowed to pick up fraction of weight. You either pick it or not.
2. The weights can contain decimal places upto 2 digits
Example (just an idea, don't remember the actual example that we discussed) :
Weights = [1.01, 3.76, 29.2, 10.04]
Profits = [10, 200, 242, 2]
W = 30
For follow up 2, it becomes:
Weights = [1.01, 3.76, 29.2, 10.04]
Profits = [1, 2, 1 ,2]
W = 30