Skip to content

Instantly share code, notes, and snippets.

Jianmin Chen jianminchen

Block or report user

Report or block jianminchen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jianminchen
jianminchen / LastStoneWeightII.py
Created Oct 8, 2019
Last stone weight II - Oct. 7, 2019, 10:00 PM mock interview
View LastStoneWeightII.py
'''
We have a collection of rocks, each rock has a positive integer weight.
Each turn, we choose any two rocks and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:
If x == y, both stones are totally destroyed;
If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x.
At the end, there is at most 1 stone left. Return the smallest possible weight of this stone (the weight is 0 if there are no stones left.)
@jianminchen
jianminchen / wordLadderFindAllPaths.java
Created Sep 25, 2019
word ladder - find all paths - mock interview as an interviewer - Sept. 24, 2019 - 10:00 PM
View wordLadderFindAllPaths.java
import java.io.*;
import java.util.*;
/*
* To execute Java, please define "static void main" on a class
* named Solution.
*
* If you need more classes, simply define them inline.
algorithm:
@jianminchen
jianminchen / wordLadderFindAllPaths.py
Created Sep 24, 2019
Word ladder - find all paths - Sept 22, 2019, 10:00 PM mock interview as an interviewer
View wordLadderFindAllPaths.py
'''
source = "good";
dest = "best";
var words = new string[] {"bood", "beod", "besd","goot","gost","gest","best"};
two paths
good->bood->beod->besd->best
good->goot->gost->gest->best
@jianminchen
jianminchen / 1200_minDiff.cs
Created Sep 22, 2019
weekly contest 155 - minimum difference - wrote in the contest
View 1200_minDiff.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace minimumDiff
{
class Program
{
@jianminchen
jianminchen / 1202_smallString_unionFind.cs
Created Sep 22, 2019
Leetcode 1202 - smallest string - union find algorithm - weekly contest 155
View 1202_smallString_unionFind.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace unionFind
{
class Program
{
@jianminchen
jianminchen / 1202_weeklyContest155.cs
Created Sep 22, 2019
Leetcode 1201 - weekly contest 155 - algorithm I wrote in the contest - I noticed the timeout issue, but I could not figure out the optimal solution.
View 1202_weeklyContest155.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace nthUglyNumber
{
class Program
{
@jianminchen
jianminchen / CountShape
Created Sep 20, 2019
count shape - count island, count shape - 9/19/2019 10:00 PM mock interview
View CountShape
count island
2 3 4
2 2 4 4
number are same, same island
the above matrix - how many islands we have
count shape - same shape
@jianminchen
jianminchen / FindAllPaths.py
Created Sep 20, 2019
Find all paths - 9/19/2019 10:00 PM mock interview
View FindAllPaths.py
def diff(w1, w2):
delta = 0
for i in range(len(w1)):
x, y = w1[i], w2[i]
if x != y:
delta += 1
return delta
@jianminchen
jianminchen / WordLadderFindAllPaths.py
Created Sep 18, 2019
Word ladder - find all paths - python - Sept. 17, 2019 10:00 PM mock interview
View WordLadderFindAllPaths.py
def say_hello():
print('Hello, World')
for i in range(5):
say_hello()
'''
source = "good";
dest = "best";
@jianminchen
jianminchen / 126Like_wordLadder_AllPath.Java
Created Sep 17, 2019
Sept. 16, 2019 - 10:00 PM Mock interview as an interviewer, the interviewee tested the code, and then passed all test cases.
View 126Like_wordLadder_AllPath.Java
import java.io.*;
import java.util.*;
class Solution {
public List<List<String>> findAllPaths(String[] dict, String src, String dest){
Set<String> set = new HashSet<>();
for(String s:dict)
set.add(s);
You can’t perform that action at this time.