FastPrepMaximize Happiness
Problems/Maximize Happiness

Maximize Happiness

Rubrik logoRubrik● HardOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Employees form a rooted company tree. Row i of employeeData is [manager, cost, leadership] for employee i + 1. Manager 0 marks the root.

Choose one employee as the manager for a client, then hire any subset of employees in that manager's subtree. The chosen manager may be hired, but does not have to be. The total hiring cost must not exceed budget.

The client's happiness is:

chosen manager's leadership * number of hired employees.

Return the maximum possible happiness.

Function

maximizeHappiness(employeeData: int[][], budget: int) → long

Examples

Example 1

employeeData = [[0, 10, 400], [1, 10, 300], [2, 15, 100], [1, 10, 60], [1, 15, 800], [2, 5, 100], [2, 5, 100]]budget = 20return = 1200

Choose employee 1 as manager and hire employees 2, 6, 7. Their total cost is 20, so happiness is 400 * 3 = 1200.

Constraints

  • 1 <= T <= 10
  • 1 <= N <=100 000 The number of Employees
  • 1 <= M <=1 000 000 000 The budget
  • 0 <= R[i] < i The RM for each employee
  • 1 <= C[i] <= M The amount of cost of each employee
  • 1 <= L[i] <= 1 000 000 000 The leadership level of each employee
  • Subtask 1: N <= 10
  • Subtask 2: N <= 3000
  • Subtask 3: Original

More Rubrik interview questions

  • Colored Rooted TreeONSITE INTERVIEW · Seen Nov 2026
  • Delete and Freeze GameOA · Seen Nov 2026
  • Delete K Subsets for Maximum ScoreOA · Seen Nov 2026
  • Distribute Elements Into Two Arrays IIOA · Seen Nov 2026
  • Minimum Replacements to Sort the ArrayOA · Seen Nov 2026
  • All Balanced Strings from Minimum Parenthesis InsertionsONSITE INTERVIEW · Seen Nov 2026
  • Insert into a Left-Complete Binary TreeONSITE INTERVIEW · Seen Oct 2026
  • Thread-Safe Request Counts by AttributeONSITE INTERVIEW · Seen Oct 2026
  • Minimum Swaps To Binary PalindromeOA · Seen Apr 2026
  • Get Minimum OperationsOA · Seen Nov 2024

Similar questions at other companies

  • Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
  • Part 2: Batch Access ReviewScale AI · OAScale AI interview questions
  • Maximum Signal Walk in a Server TreeTower Research Capital · OA
  • Binary Tree CamerasAmazon · OA · PHONE SCREEN
  • Minimum Satellite Data Transfer IterationsHSBC · OAHSBC interview questions
  • Maximum Sum Path Between Two Leaf NodesGoogle · OAGoogle interview questions
  • Maximum Strength of Every NeuronMicrosoft · OAMicrosoft interview questions
  • Tree PointsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Binary Tree Maximum Path SumArcesium · OAArcesium interview questions
  • Tree Node With Maximum BeautyC3.ai · OAC3.ai interview questions
All Rubrik interview questionsSee Rubrik hiring insights
Saved
class Solution {
    public long maximizeHappiness(int[][] employeeData, int budget) {
      // write your code here
    }

}
Checking account…