This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.Set; | |
import org.jgrapht.graph.DefaultEdge; | |
import org.jgrapht.graph.SimpleGraph; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
ggplot.ccdf <- function(data, xlab='x', ylab='CCDF', xbreaks=NULL, ybreaks=NULL, c=NULL, alpha=NULL) { | |
x <- sort(data) | |
y <- 1-((1:(length(x))-1)/length(x)) | |
df <- data.frame(x=x, y=y) | |
scale_x <- scale_x_log10() | |
if (!is.null(xbreaks)) { | |
scale_x <- scale_x_log10(breaks=xbreaks) | |
} | |
scale_y <- scale_y_log10() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Node lastVisted = null; | |
void convertTree(Node root) { | |
if (root == null) { | |
return; | |
} | |
convertTree(root.left); | |
if (lastVisited != null && lastVisited.right == null) { | |
lastVisited.right = root; | |
lastVisited.t |= RIGHT_CONVERTED; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
private HashMap<String, Boolean> palindromeCache; | |
private HashMap<String, Integer> resultCache; | |
public int minCut(String s) { | |
// Note: The Solution object is instantiated only once and is reused by each test case. | |
palindromeCache = new HashMap<String, Boolean>(); | |
resultCache = new HashMap<String, Integer>(); | |
return minCutRecursive(s); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
array anagramBuckets(array strings) | |
Write a function to group an array of strings by anagrams. | |
Input: An array of strings (possibly with duplicates) | |
Output: An array of arrays. Each array contains a set of strings from the input array that are anagrams of each other. The output should not contain any duplicates. | |
Example: | |
Input: ('abc', 'bac', 'xyz', 'xyz') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exec = require('child_process').exec; | |
var mongoose = require('mongoose'); | |
desc('Runs the mocha unit tests'); | |
task('test', function(params) { | |
var proc = exec('mocha --recursive --colors'); | |
proc.stdout.pipe(process.stdout, { end: false }); | |
proc.stderr.pipe(process.stderr, { end: false }); | |
proc.on('exit', process.exit); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public String longestPalindrome(String s) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
String longest = ""; | |
for(int i = 0; i < s.length(); i++) { | |
int j; | |
// pivot at a char | |
for(j = 1; i - j >=0 && i + j < s.length(); j++) { | |
if(s.charAt(i - j) != s.charAt(i + j)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { | |
* val = x; | |
* next = null; | |
* } | |
* } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int lengthOfLongestSubstring(String s) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
String longest = ""; | |
int i = 0; | |
while(i < s.length()) { | |
HashMap<Character, Integer> map = new HashMap<Character, Integer>(); | |
map.put(s.charAt(i), i); | |
int j; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int lengthOfLongestSubstring(String s) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
String longest = ""; | |
for(int i = 0; i < s.length(); i++) { | |
HashSet<Character> set = new HashSet<Character>(); | |
set.add(s.charAt(i)); | |
int j; | |
for(j = i + 1; j < s.length(); j++) { |
NewerOlder