{ "data": { "question": { "questionId": "690", "questionFrontendId": "690", "boundTopicId": null, "title": "Employee Importance", "titleSlug": "employee-importance", "content": "

You have a data structure of employee information, including the employee's unique ID, importance value, and direct subordinates' IDs.

\n\n

You are given an array of employees employees where:

\n\n\n\n

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

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: employees = [[1,5,[2,3]],[2,3,[]],[3,3,[]]], id = 1\nOutput: 11\nExplanation: Employee 1 has an importance value of 5 and has two direct subordinates: employee 2 and employee 3.\nThey both have an importance value of 3.\nThus, the total importance value of employee 1 is 5 + 3 + 3 = 11.\n
\n\n

Example 2:

\n\"\"\n
\nInput: employees = [[1,2,[5]],[5,-3,[]]], id = 5\nOutput: -3\nExplanation: Employee 5 has an importance value of -3 and has no direct subordinates.\nThus, the total importance value of employee 5 is -3.\n
\n\n

 

\n

Constraints:

\n\n\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Medium", "likes": 1569, "dislikes": 1231, "isLiked": null, "similarQuestions": "[{\"title\": \"Nested List Weight Sum\", \"titleSlug\": \"nested-list-weight-sum\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]", "exampleTestcases": "[[1,5,[2,3]],[2,3,[]],[3,3,[]]]\n1\n[[1,2,[5]],[5,-3,[]]]\n5", "categoryTitle": "Algorithms", "contributors": [], "topicTags": [ { "name": "Hash Table", "slug": "hash-table", "translatedName": null, "__typename": "TopicTagNode" }, { "name": "Depth-First Search", "slug": "depth-first-search", "translatedName": null, "__typename": "TopicTagNode" }, { "name": "Breadth-First Search", "slug": "breadth-first-search", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for Employee.\nclass Employee {\npublic:\n int id;\n int importance;\n vector subordinates;\n};\n*/\n\nclass Solution {\npublic:\n int getImportance(vector employees, int id) {\n \n }\n};", "__typename": "CodeSnippetNode" }, { "lang": "Java", "langSlug": "java", "code": "/*\n// Definition for Employee.\nclass Employee {\n public int id;\n public int importance;\n public List subordinates;\n};\n*/\n\nclass Solution {\n public int getImportance(List employees, int id) {\n \n }\n}", "__typename": "CodeSnippetNode" }, { "lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for Employee.\nclass Employee(object):\n def __init__(self, id, importance, subordinates):\n \t#################\n :type id: int\n :type importance: int\n :type subordinates: List[int]\n #################\n self.id = id\n self.importance = importance\n self.subordinates = subordinates\n\"\"\"\n\nclass Solution(object):\n def getImportance(self, employees, id):\n \"\"\"\n :type employees: List[Employee]\n :type id: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode" }, { "lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for Employee.\nclass Employee:\n def __init__(self, id: int, importance: int, subordinates: List[int]):\n self.id = id\n self.importance = importance\n self.subordinates = subordinates\n\"\"\"\n\nclass Solution:\n def getImportance(self, employees: List['Employee'], id: int) -> int:\n ", "__typename": "CodeSnippetNode" }, { "lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for Employee.\nclass Employee {\n public int id;\n public int importance;\n public IList subordinates;\n}\n*/\n\nclass Solution {\n public int GetImportance(IList employees, int id) {\n \n }\n}", "__typename": "CodeSnippetNode" }, { "lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for Employee.\n * function Employee(id, importance, subordinates) {\n * this.id = id;\n * this.importance = importance;\n * this.subordinates = subordinates;\n * }\n */\n\n/**\n * @param {Employee[]} employees\n * @param {number} id\n * @return {number}\n */\nvar GetImportance = function(employees, id) {\n \n};", "__typename": "CodeSnippetNode" }, { "lang": "Ruby", "langSlug": "ruby", "code": "=begin\n# Definition for Employee.\nclass Employee\n attr_accessor :id, :importance, :subordinates\n def initialize( id, importance, subordinates)\n @id = id\n @importance = importance\n @subordinates = subordinates\n end\nend\n=end\n\n# @param {Employee} employees\n# @param {Integer} id\n# @return {Integer}\ndef get_importance(employees, id)\n \nend", "__typename": "CodeSnippetNode" }, { "lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for Employee.\n * public class Employee {\n * public var id: Int\n * public var importance: Int\n * public var subordinates: [Int]\n * public init(_ id: Int, _ importance: Int, _ subordinates: [Int]) {\n * self.id = id\n * self.importance = importance\n * self.subordinates = subordinates\n * }\n * }\n */\n\nclass Solution {\n func getImportance(_ employees: [Employee], _ id: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode" }, { "lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for Employee.\n * type Employee struct {\n * Id int\n * Importance int\n * Subordinates []int\n * }\n */\n\nfunc getImportance(employees []*Employee, id int) int {\n \n}", "__typename": "CodeSnippetNode" }, { "lang": "Scala", "langSlug": "scala", "code": "/*\n// Definition for Employee.\nclass Employee() {\n var id: Int = 0\n var importance: Int = 0\n var subordinates: List[Int] = List()\n};\n*/\n\nobject Solution {\n def getImportance(employees: List[Employee], id: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode" }, { "lang": "Kotlin", "langSlug": "kotlin", "code": "/*\n *\t// Definition for Employee.\n *\tclass Employee {\n *\t\tvar id:Int = 0\n *\t\tvar importance:Int = 0\n *\t\tvar subordinates:List = listOf()\n *\t}\n */\n\nclass Solution {\n fun getImportance(employees: List, id: Int): Int {\n \n }\n}", "__typename": "CodeSnippetNode" }, { "lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for Employee.\n * class Employee {\n * public $id = null;\n * public $importance = null;\n * public $subordinates = array();\n * function __construct($id, $importance, $subordinates) {\n * $this->id = $id;\n * $this->importance = $importance;\n * $this->subordinates = $subordinates;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Employee[] $employees\n * @param Integer $id\n * @return Integer\n */\n function getImportance($employees, $id) {\n \n }\n}", "__typename": "CodeSnippetNode" }, { "lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Employee.\n * class Employee {\n * id: number\n * importance: number\n * subordinates: number[]\n * constructor(id: number, importance: number, subordinates: number[]) {\n * this.id = (id === undefined) ? 0 : id;\n * this.importance = (importance === undefined) ? 0 : importance;\n * this.subordinates = (subordinates === undefined) ? [] : subordinates;\n * }\n * }\n */\n\nfunction getImportance(employees: Employee[], id: number): number {\n\t\n};", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"172.2K\", \"totalSubmission\": \"269.3K\", \"totalAcceptedRaw\": 172217, \"totalSubmissionRaw\": 269263, \"acRate\": \"64.0%\"}", "hints": [], "solution": { "id": "303", "canSeeDetail": true, "paidOnly": false, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "[[1,5,[2,3]],[2,3,[]],[3,3,[]]]\n1", "metaData": "{\n \"name\": \"getImportance\",\n \"params\": [\n {\n \"name\": \"employees\",\n \"type\": \"list\"\n },\n {\n \"name\": \"id\",\n \"type\": \"integer\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"cpp\",\n \"java\",\n \"python\",\n \"ruby\",\n \"python3\",\n \"kotlin\",\n \"scala\",\n \"csharp\",\n \"javascript\",\n \"swift\",\n \"golang\",\n \"php\",\n \"typescript\"\n ],\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": true, "enableTestMode": false, "enableDebugger": true, "envInfo": "{\"cpp\": [\"C++\", \"

Compiled with clang 11 using the latest C++ 17 standard.

\\r\\n\\r\\n

Your code is compiled with level two optimization (-O2). AddressSanitizer is also enabled to help detect out-of-bounds and use-after-free bugs.

\\r\\n\\r\\n

Most standard library headers are already included automatically for your convenience.

\"], \"java\": [\"Java\", \"

OpenJDK 17 . Java 8 features such as lambda expressions and stream API can be used.

\\r\\n\\r\\n

Most standard library headers are already included automatically for your convenience.

\\r\\n

Includes Pair class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.

\"], \"python\": [\"Python\", \"

Python 2.7.12.

\\r\\n\\r\\n

Most libraries are already imported automatically for your convenience, such as array, bisect, collections. If you need more libraries, you can import it yourself.

\\r\\n\\r\\n

For Map/TreeMap data structure, you may use sortedcontainers library.

\\r\\n\\r\\n

Note that Python 2.7 will not be maintained past 2020. For the latest Python, please choose Python3 instead.

\"], \"csharp\": [\"C#\", \"

C# 10 with .NET 6 runtime

\\r\\n\\r\\n

Your code is compiled with debug flag enabled (/debug).

\"], \"javascript\": [\"JavaScript\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use datastructures-js/priority-queue and datastructures-js/queue.

\"], \"ruby\": [\"Ruby\", \"

Ruby 3.1

\\r\\n\\r\\n

Some common data structure implementations are provided in the Algorithms module: https://www.rubydoc.info/github/kanwei/algorithms/Algorithms

\"], \"swift\": [\"Swift\", \"

Swift 5.5.2.

\"], \"golang\": [\"Go\", \"

Go 1.17.6.

\\r\\n\\r\\n

Support https://godoc.org/github.com/emirpasic/gods library.

\"], \"python3\": [\"Python3\", \"

Python 3.10.

\\r\\n\\r\\n

Most libraries are already imported automatically for your convenience, such as array, bisect, collections. If you need more libraries, you can import it yourself.

\\r\\n\\r\\n

For Map/TreeMap data structure, you may use sortedcontainers library.

\"], \"scala\": [\"Scala\", \"

Scala 2.13.7.

\"], \"kotlin\": [\"Kotlin\", \"

Kotlin 1.3.10.

\"], \"php\": [\"PHP\", \"

PHP 8.1.

\\r\\n

With bcmath module

\"], \"typescript\": [\"Typescript\", \"

TypeScript 4.5.4, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2020 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }