View on GitHub

leetcode-diaries

A journal to record the solution of the various Leetcode problems solved over the course of time.

Employee Importance

Leetcode problem 690; Difficulty: Easy

Problem Statement

You have a data structure of employee information, which includes the employee’s unique id, their importance value, and their direct subordinates’ id.

You are given an array of employees employees where:

Given an integer id that represents the ID of an employee, return the total importance value of this employee and all their subordinates.

Constraints:

Example 1:

image

Input: employees = [[1,5,[2,3]],[2,3,[]],[3,3,[]]], id = 1

Output: 11

Explanation:

Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3.
They both have importance value 3.
So the total importance value of employee 1 is 5 + 3 + 3 = 11.

Example 2:

image

Input: employees = [[1,2,[5]],[5,-3,[]]], id = 5

Output: -3

Submitted Solution

The implemented solution received the following rating on Leetcode:

image