Skip to content

Instantly share code, notes, and snippets.

Avatar

Jianmin Chen jianminchen

View GitHub Profile
@jianminchen
jianminchen / maximumLineInMatrix.cs
Created Nov 26, 2020
maximum line in matrix - Nov. 25, 2020
View maximumLineInMatrix.cs
public int LongestLine(int[][] M) {
if(M == null || M.Length == 0 || M[0].Length == 0)
{
return 0;
}
var rows = M.Length;
var columns = M[0].Length;
var dpH = new int[rows][];
@jianminchen
jianminchen / Leetcode737SentenceSimilarity.cs
Created Nov 19, 2020
Leetcode 737 Sentence Similarity - C# solution -
View Leetcode737SentenceSimilarity.cs
public class Solution {
/// <summary>
/// Nov. 19, 2020
/// study code
/// https://leetcode.com/problems/sentence-similarity-ii/solution/
/// Time Complexity: O(NP), where N is the maximum length of words1 and words2,
/// and P is the length of pairs. Each of N searches could search the entire graph.
/// </summary>
/// <param name="words1"></param>
/// <param name="words2"></param>
@jianminchen
jianminchen / 801MinimumSwapsToMakeSequencesIncreasing.js
Created Nov 16, 2020
Mock interview Nov. 15, 2020 10:00 PM as an interviewer
View 801MinimumSwapsToMakeSequencesIncreasing.js
const _ = require('lodash');
function sayHello() {
console.log('Hello, World');
}
_.times(5, sayHello);
/*
@jianminchen
jianminchen / Leetcode1657-TwoStringClose.cs
Created Nov 15, 2020
unfinished code - 1657 - two string close
View Leetcode1657-TwoStringClose.cs
public class Solution {
public bool CloseStrings(string word1, string word2) {
if(word1.Length != word2.Length)
return false;
var map = new int[26];
for(int i = 0; i < 26; i++)
{
map[i] = -1;
}
@jianminchen
jianminchen / MinimumWindowSubsequence
Created Nov 11, 2020
Mock interview Nov. 10, 2020 10:00 PM
View MinimumWindowSubsequence
Problem statement:
Given a string S and a string t , find the minimum window substring in S which contains all the characters of the string T in the same order.
import java.io.*;
import java.util.*;
class Solution {
public static void main(String[] args) {
}
@jianminchen
jianminchen / wordBreak.Java
Created Nov 2, 2020
word break - Java - mock interview - BFS algorithm
View wordBreak.Java
/*
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
Note:
The same word in the dictionary may be reused multiple times in the segmentation.
You may assume the dictionary does not contain duplicate words.
Example 1:
Input: s = "leetcode", wordDict = ["leet", "code"]
@jianminchen
jianminchen / 425WordSquare.cs
Last active Oct 21, 2020
425 word square - C# code - Trie - I took time to figure out prefix.
View 425WordSquare.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _435_word_square
{
class Program
{
@jianminchen
jianminchen / 358rearrangeStringKDistance.cs
Created Oct 21, 2020
358 Rearrange string k distance - using brute force - search all available and then find optimal one
View 358rearrangeStringKDistance.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _358_rearrange_string_k_distance_apart
{
class Program
@jianminchen
jianminchen / 358RearrangeStringKDistance.cs
Created Oct 21, 2020
358 rearrange string k distance - using maximum heap, C# SortedSet, LinkedList and Array
View 358RearrangeStringKDistance.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _358_Heap_LinkedList
{
class Program
{
@jianminchen
jianminchen / SearchFindshortestPathFriend
Created Oct 17, 2020
Social graph - system design interview
View SearchFindshortestPathFriend
This editor is synced in real time with your peer.
Use it to share thoughts and resources, such as:
- Features scope
- API design
- Pseudo code for specific components
- Data model/schema
- Back-of-the-envelope calculations
- Reference links
- Link to whiteboard or diagram such as https://sketchboard.me/new