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
#!/usr/bin/env bash | |
PKG_LIST_DIR=~/Downloads/package_list.txt | |
INSTALL="sudo apt-get" | |
REMOVE="sudo apt-get -r" | |
SEARCH="apt-cache search" | |
# Search for a package in the package manager | |
search(){ | |
for PKG in "$@" |
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.util.ArrayList; | |
class Staircase { | |
/** | |
* Can take one or two steps to get to the top of the staircase | |
* write function num_ways(N) | |
*/ | |
public static int num_ways(int n){ | |
if (n==0 || n==1) | |
return 1; |
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
def arrayProduct(a=[],*args): | |
result = [0] * len(a) | |
product = 1 | |
for i in range (0,len(a)): | |
product = product * a[i] | |
for j in range (0,len(a)): | |
result[j] = product / a[j] | |
return result | |
a = [1,2,3,4,5] |
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.util.ArrayList; | |
import java.util.Arrays; | |
class ListAddition { | |
public static boolean list_add(int k, int[] list){ | |
for (int i=0; i<list.length; i++){ | |
for (int j=i+1; j<list.length; j++){ | |
if (list[i]+list[j]==k) | |
return true; | |
} |
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.util.Scanner; | |
/* | |
Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree. | |
For example, given the following Node class | |
class Node: | |
def __init__(self, val, left=None, right=None): | |
self.val = val |
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
def cons(a, b): | |
return lambda f: f(a, b) | |
def car(f): | |
return f(lambda a, b: a) | |
def cdr(f): | |
return f(lambda a, b: b) | |
a, b = (int(n) for n in input().split(',')) |
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
class LargestSum { | |
public static int get_sum(int[] arr, int n){ | |
int incl = arr[0]; // Max sum including the previous element | |
int excl = 0; // Max sum excluding the previous element | |
int excl_new; | |
int i; | |
for (i=0; i<n; i++){ | |
/* current max excluding i */ | |
excl_new = (incl>excl) ? incl:excl; |
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
/** | |
A unival tree (which stands for "universal value") is a tree where all nodes under it have the same value. | |
Given the root to a binary tree, count the number of unival subtrees. | |
For example, the following tree has 5 unival subtrees: | |
0 | |
/ \ | |
1 0 |
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 sched, time | |
s = sched.scheduler(time.time, time.sleep) | |
def print_time(): print ("From print_time", time.time()) | |
def job_scheduler(f,n): | |
s.enter(n, 1, f, ()) | |
s.run() | |
job_scheduler(print_time, 10) |
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
class BinaryTreeLock | |
attr_accessor :locked, :left, :right | |
def initialize(left=nil, right=nil, unlocked) | |
@left = left | |
@right = right | |
@unlocked = unlocked | |
end | |
def lock |
OlderNewer