Amazon Coding Interview Question
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-04-24Added By Anonymous
Source: Link
Company: Amazon
Role: sde i, sde ii
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Got asked the following in a recent interview.
There is a boss that wants to give gift to their employees. There are n employees and at least one should get a gift. Employees have one directional relationships with other employees. Each gift costs price amount.
If you give gift to an employee then their friends would also need to be given a gift. Boss wants to spend minimum amount in giving these gifts.
Example:
n = 4
Relationships:
1 2
1 3
2 3
3 4
Price: 200
I guess answer in this example is 200 as you can give it to 4 and 4 has no outward edges.