Skip to content

Instantly share code, notes, and snippets.

Jianmin Chen jianminchen

View GitHub Profile
@jianminchen
jianminchen / ContructBinaryTreeFromPostOrderInOrderList.py
Created Aug 2, 2020
August 2, 2020 - construct binary tree from post order and inorder traversal lists - August 2, 2020 2:00 PM mock interview
View ContructBinaryTreeFromPostOrderInOrderList.py
class TreeNode:
def __init__(self, val):
self.left = None
self.right = None
self.val = val
def get_binary_tree(l, r, postorder):
if not inorder[l:r]: return None
root = TreeNode(postorder.pop()) # 3 - last one in stack, l, r value
@jianminchen
jianminchen / System Design lesson one
Created Jul 25, 2020
System design - lesson one - July 25 2020
View System Design lesson one
2:51 PM
How would you build a website for a bakery?
Breakfast foods, croissants, bread
Category - website
10 - 20 people max a day
20 - 30 products
Category - price, product in detail <-
Should write down -
@jianminchen
jianminchen / FindLongestRepeatedSubstring.java
Created Jul 23, 2020
shared by my friend - Ph.D. Ex-Microsoft, Amazon engineer, Find longest repeated substring with overlapping - Leetcode https://github.com/jianminchen/100-hard-level-algorithms-2018-summer-campaign/tree/master/LongestRepeatedSubstring-overlap
View FindLongestRepeatedSubstring.java
class Solution {
int a = 26, mod = 1<<30;
public String longestDupSubstring(String S) {
int lo = 1, hi = S.length()-1;
while(lo<=hi){
int mid = lo+(hi-lo)/2, startIndex = search(S,mid);
if(startIndex==-1){
hi = mid-1;
}
else{
@jianminchen
jianminchen / cloneGraph.cs
Created Jul 19, 2020
clone graph - mock interview on July 19, 2020 10:00 AM - the idea is correct, and logic is working...
View cloneGraph.cs
using System;
// To execute C#, please define "static void Main" on a class
// named Solution.
class Solution
{
static void Main(string[] args)
{
for (var i = 0; i < 5; i++)
@jianminchen
jianminchen / FourSum.cs
Created Jul 18, 2020
Four sum - C# code
View FourSum.cs
public IList<IList<int>> FourSum(int[] nums, int target) {
if(nums == null || nums.Length < 4 )
return new List<IList<int>>();
var fourNumbers = new List<IList<int>>();
Array.Sort(nums);
var length = nums.Length;
for(int i = 0; i < length - 3; i++)
@jianminchen
jianminchen / SufficientPathTreeAlgo.java
Created Jul 17, 2020
July 15, 2020 - 10:00 PM mock interview - the interviewee is Microsoft SDE II with two year experience
View SufficientPathTreeAlgo.java
import java.io.*;
import java.util.*;
class Solution {
public static void main(String[] args) {
ArrayList<String> strings = new ArrayList<String>();
strings.add("Hello, World!");
strings.add("Welcome to CoderPad.");
strings.add("This pad is running Java " + Runtime.version().feature());
@jianminchen
jianminchen / IslandPerimeter.java
Created Jul 17, 2020
July 15, 2020 - 10:00 PM mock interview - interview is Microsoft SDE II, two years experience - Excellent problem solving, bug-free code
View IslandPerimeter.java
import java.io.*;
import java.util.*;
/*
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water.
Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).
The island doesn't have "lakes" (water inside that isn't connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.
@jianminchen
jianminchen / Mock interview - find third largest maximum number
Created Jul 12, 2020
Mock interview - find third largest maximum number - July 11, 2020 - 6:40 PM - 30 minutes code question
View Mock interview - find third largest maximum number
7:03 PM
Intention
Communication, ask clarification, brute force -> optimal, run test cases - simple, catch all bugs
Do not fake testing…
7:06 PM
414. Third Maximum Number
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).
Array - not distinct
[1, 1, 2,2, 3] - third maximum number
@jianminchen
jianminchen / Leetcode731_MyCalendarII.cs
Created Jul 10, 2020
Leetcode 731 - My calendar - mock interview 10:0 PM - Cisco tech lead as an interviewer
View Leetcode731_MyCalendarII.cs
using System;
// To execute C#, please define "static void Main" on a class
// named Solution.
class Solution
{
static void Main(string[] args)
{
for (var i = 0; i < 5; i++)
@jianminchen
jianminchen / JumpToLastStone.py
Created Jul 10, 2020
Interviewer shared his solution and he also shared his tips -
View JumpToLastStone.py
const _ = require('lodash');
function sayHello() {
console.log('Hello, World');
}
_.times(5, sayHello);
var canCross = function(stones) {
let map = new Map();
You can’t perform that action at this time.