Posts

Mapping a Tree to a HashTable data structure II

Another problem where it gets easier if you map the tree to a HashTable. Keep in mind that this is an N-Ary tree, not binary. After that it is a straightforward pre-order depth-first-search (Pre-Order DPS). Code is down below, cheers, ACC. Finish Time of Tasks I - LeetCode You are given an integer n representing the number of tasks in a project, numbered from 0 to n - 1 . These tasks are connected as a tree rooted at task 0. This is represented by a 2D integer array edges of length n - 1 , where edges[i] = [u i , v i ] indicates that task u i is the parent of task v i . You are also given an array baseTime of length n , where baseTime[i] represents the time to complete task i . The finish time of each task is calculated as follows: Leaf task: The finish time is baseTime[i] . Non-leaf task: Let earliest be the minimum finish time among its children, and latest be the maximum finish time among its children. Let ownDuration be (latest - earliest) + baseTime[i] . The finish ti...