Skip to content

Instantly share code, notes, and snippets.

@capcase
capcase / gist:1643512
Created January 19, 2012 22:54
myth words matching
boolean Solution(Map<Char, int> sofar, List<Char> rest, int k) {
if (rest.isEmpty()) {
return validateAnswer(sofar);
}
k = k+1;
Char a = rest.poll();
int[] candidates = findCandidates(sofar);
for(int i=0; i< candidates.length; i++)
@capcase
capcase / gist:1618630
Created January 16, 2012 01:55
value path in BST tree
void printPath(Node node, int target) {
List<Node> path = new ArrayList<Node>();
traversePath(node, target, path, 0);
}
void traversePath(Node node, int target, List<Node> path, level) {
if (node == null) return;
path.add(level, node);
@capcase
capcase / countNumbers
Created January 14, 2012 19:24
count possible ways to add numbers.
input :
Integer[] src;
int TARGER
countNumbers(src, 0, currentPath, results);
countNumbers(Integer[] src, int index, List<Integer> currentPath, List<List<Integer>> results)
{
List<Integer> path = new ArrayList<Integer>();
path.addAll(currentPath);
@capcase
capcase / gist:1598920
Created January 12, 2012 05:16
words transform approach
int string_compare(char *s, char *t, int i, int j, )
// s is inut text
// t is target
{
int k; /* counter */
int opt[3]; /* cost of the three options */
int lowest_cost; /* lowest cost */
if (i == 0) return(j * cost.insertion);
if (j == 0) return(i * cost.deletion);
@capcase
capcase / sliding_window.java
Created December 16, 2011 07:09
sliding window
void sliding_window(int [] a, int[] b){
for(i=0; i b[i-w+1] = Q.top();
while(!Q.empty() && Q.back() < a[i]) {
Q.popBack();
}
Q.pushBack(i);
while(!Q.empty() && Q.front() Q.popFront();
}
} // end for loop
b[n-w] = Q.top();