Skip to content

Instantly share code, notes, and snippets.

View vimncent's full-sized avatar
🏡
Working from home

Vincent Le vimncent

🏡
Working from home
View GitHub Profile
public int findMax(int n, int[] arr) {
// let freqMap be a map where the keys are the elements in arr
// and the values are its frequency or the number of occurences in arr
List<Integer> list = new ArrayList<>();
for (int i = 1; i <= n; i++) {
if (!freqMap.contains(i)) continue;
for (int count = 0; count < freqMap.get(i); count++) {
list.add(i);
@vimncent
vimncent / solution.md
Last active July 12, 2020 15:42
Deepest Leaves Sum

Question

Given a binary tree, return the sum of values of its deepest leaves.

Solutions

Recursive Depth First Search

Intuition

Find the largest depth first, then sum up each node at the largest depth

Algorithm

@vimncent
vimncent / tree.html
Last active March 28, 2018 20:41
Interactive NGS Simulator Tree
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Tree Example</title>
<style>
.node {
cursor: pointer;
}
.node circle {
@vimncent
vimncent / mesopelagic.sh
Last active March 27, 2018 02:45
CS 4884 HW
#!/bin/bash
#PBS -l walltime=24:00:00
#PBS -l procs=4
#PBS -q normal_q
#PBS -A cs4884s18
#PBS -W group_list=newriver
# Purge existing modules.
module purge
@vimncent
vimncent / FastViromeExplorer.out
Created February 10, 2018 18:30
Output when running FastViromeExplorer shell script
This file has been truncated, but you can view the full file.
# Output for running the command:
# > kallisto quant -i test/testset-kallisto-index.idx -o test-output --pseudobam test/reads_1.fq test/reads_2.fq | samtools view -bS - | samtools view -h -F 0x04 -b - | samtools sort - -o test-output/FastViromeExplorer-reads-mapped-sorted.sam > foo
[quant] fragment length distribution will be estimated from the data
[index] k-mer length: 31
[index] number of targets: 97
[index] number of k-mers: 515,417
[index] number of equivalence classes: 101
[quant] running in paired-end mode
@vimncent
vimncent / index.js
Created February 6, 2018 17:44
sample express server with mongodb
var express = require('express');
var mongojs = require('mongojs');
var db = mongojs(process.env.MONGO_URL || 'mongodb://localhost:27017/local');
var app = express();
app.use('/public', express.static('public'))
app.listen(3000, () => console.log('listening on *:3000'));
@vimncent
vimncent / test.sh
Created April 21, 2017 00:07
Graph Shell Script
#!/bin/bash
echo "Compiling source code"
javac SSAD.java
echo "Running test"
for i in `seq 1 1 $1`; do
java -jar SSADGen.jar Graph${i}.txt profResults${i}.txt
java SSAD Graph${i}.txt log${i}.txt
#!/bin/bash
echo "Compiling source code"
javac ../src/Minor/P2/DS/BST.java
mv ../src/Minor/P2/DS/*.class Minor/P2/DS
java -jar BSTGenerator.jar
echo "Running test"
java testDriver
@vimncent
vimncent / kmp.java
Created December 30, 2016 22:30
Knuth Morris Pratt string searching algorithm in Java
import java.util.Scanner;
public class KMP {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
String search = kb.next();
String target = kb.next();
int result = KMP(search, target);
if (result == -1) {
System.out.println("NO");
@vimncent
vimncent / message.js
Created December 25, 2016 04:24
React Native Socket.io Existing Messages
socket.on('connection', () => {
var messages = db.collection('messages').find({
chatId: chatId // We want all the messages for that room.
}).sort({
createdAt: -1 // It's best not to assume that it is in order.
});
socket.emit('message', messages);
});