Leetcode 690 Employee Importance Solution

This is my solution in PHP.

/**
* Definition for Employee.
* class Employee {
*     public $id = null;
*     public $importance = null;
*     public $subordinates = array();
*     function __construct($id, $importance, $subordinates) {
*         $this->id = $id;
*         $this->importance = $importance;
*         $this->subordinates = $subordinates;
*     }
* }
*/

class Solution {
/**
 * @param Employee[] $employees
 * @param Integer $id
 * @return Integer
 */

function getImportance($employees, $id) {
  if (empty($employees)) return 0;
  $emap = [];
  foreach ($employees as $e) {
    $emap[$e->id] = $e;
  }

  return $this->recurse($emap, $id);
 }

function recurse($emap, $id) {
  $e = $emap[$id];
  $ans = $e->importance;
  foreach ($e->subordinates as $sub) {
    $ans += $this->recurse($emap, $sub);
  }
  return $ans;
 }
}

My Writing & Coding Workflow | the cedar ledge

http://jacobzelko.com/workflow/

This is awesome. I need to emulate this because I enjoy working in shell more than in gui.


LeetCode 42. Trapping Rain Water


LeetCode 11. Container With Most Water


LeetCode 1. Two Sum

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function(nums, target) {
    const numsToFind = {};
    
    for (let i=0; i<nums.length; i++) {
        const numToFind = nums[i];
        if (numsToFind[numToFind] >= 0) {
            return [i, numsToFind[numToFind]];
        }
        numsToFind[target - numToFind] = i;    
    }
};


LeetCode 1249. Minimum Remove to Make Valid Parentheses


LeetCode #20 Valid Parentheses


Brain is too tired to do any LeetCode tonight

Brain is too tired to do any LeetCode tonight. LeetCode challenges are fun but feel pointless. I don’t want to get burned out, so taking a break today.


Jane Street Market Prediction

Found this challenge on Kaggle. Probably a good learning opportunity.

Test your model against future real market data

Source: Jane Street Market Prediction


WTF Happened In 1971?

Visit the post for more.

Source: WTF Happened In 1971?