Skip to main content
All Questions

Maximize the total salary after department-wide increment or decrement tasks on a company hierarchy.

Unlock detailed company stats for this questionUpgrade

Every employee reports to exactly one manager except the CEO, forming a proper hierarchy. Everyone's salary starts at 0. You perform a set of tasks; each task increments or decrements salary, but not for a specific employee: it applies to that employee's whole department. Choose how to apply the tasks so salaries are maximized, and return the sum of everyone's salary after the transformation. Every employee can also be a manager.

Input: first line has the number of employees and number of tasks (3 1). Then n-1 lines 'a b' meaning a is the manager of b (1 2, 1 3). Then each task: number of candidate employees, the increment value, and the employee list (2 10 2 3).

Format · Technical round.

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.