Skip to content

Instantly share code, notes, and snippets.

View jianminchen's full-sized avatar

Jianmin Chen jianminchen

View GitHub Profile
@jianminchen
jianminchen / LowestCommonAncestor.cs
Created February 23, 2022 18:22
Given a binary tree with parent node, given two nodes p and q, find lowest common ancestor. Aim at space O(1) solution. - interviewing.io mock interview, Feb. 22, 2022
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LowestCommonAncestorWithParent
{
class Program
@jianminchen
jianminchen / BuildTrieUsingCsvImport.cs
Created July 2, 2021 00:47
Build a trie using csv file with million record import - test the code using Excel -> table -> filter -> startsWith
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace csvReader
@jianminchen
jianminchen / TrieImplementation.cs
Created June 28, 2021 23:28
Trie - Read csv file and then return BFS results starting with prefix >= 3 chars at least
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace csvReader
{
@jianminchen
jianminchen / FindLargestMergedIsland.cs
Last active April 17, 2021 04:18
Mock interview - Interviewer: an engineer who prepares for Facebook onsite next week - April 16, 2021, 8:10 PM - 8:40PM
//We have a binary matrix conatining only 0 & 1, find the larget conected area of 1 if we can convert
// exactly 1 zero into 1 in the matrix.
//You can travel up down lwft and right.
//3 3 (5) 2
//0 3 0 2
//ans == 6
// 0, 1, - 1 island node
Var map = new Dictionary< int, int>();
@jianminchen
jianminchen / maximumLineInMatrix.cs
Created November 26, 2020 02:21
maximum line in matrix - Nov. 25, 2020
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 November 19, 2020 23:31
Leetcode 737 Sentence Similarity - C# solution -
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 November 16, 2020 07:00
Mock interview Nov. 15, 2020 10:00 PM as an interviewer
const _ = require('lodash');
function sayHello() {
console.log('Hello, World');
}
_.times(5, sayHello);
/*
@jianminchen
jianminchen / Leetcode1657-TwoStringClose.cs
Created November 15, 2020 04:18
unfinished code - 1657 - two string close
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 November 11, 2020 19:26
Mock interview Nov. 10, 2020 10:00 PM
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 November 2, 2020 05:16
word break - Java - mock interview - BFS algorithm
/*
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"]