Skip to main content
All Questions

Maximize an event's total fun with no employee attending alongside their direct manager.

Unlock detailed company stats for this questionUpgrade

Organizational hierarchy with the CEO at the top. There are n employees numbered 0 to n-1. Given arrays manager and fun_rating of length n: manager[i] is the manager of employee i (manager[0] = -1, the CEO has none) and fun_rating[i] is the fun rating of employee i. Total fun is the sum of the fun ratings of all participating employees. An employee and their direct manager cannot participate together. Find the max total fun and also return the list of participating employee IDs; if there are multiple solutions, any is fine. Example: manager = [-1, 0, 0, 1, 1, 2, 2], fun_rating = [5, 2, 4, 7, 2, 10, 9].

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.