Skip to content

Instantly share code, notes, and snippets.

View h2rashee's full-sized avatar

Harris Rasheed h2rashee

View GitHub Profile
@h2rashee
h2rashee / TempCleanup.py
Last active August 29, 2015 14:08
Removes old files from a directory
# Question
#
# We have many applications running that store temporary files in /var/tmp, which fills up over time.
#
# Write a function that cleans out files older than a user specified number of days and
# removes empty directories recursively.
#
import os
import sys
@h2rashee
h2rashee / bst.cc
Last active August 29, 2015 14:08
BST Problems
/* Question
*
* Given a binary search tree (BST), write the following two methods:
*
* 1. Given a pointer to a node in the tree, find the smallest element.
* 2. Given a pointer to a node in the tree, find the next highest element in key value.
* 3. Do an in-order traversal of the tree
* */
struct Node {
@h2rashee
h2rashee / harrisify.py
Created November 1, 2014 18:08
Given a stream of text, add a newline after any form of end of sentence punctuation
import fileinput
endOfSentence = ['.', '!', '?']
def charInWord(word):
for char in endOfSentence:
if char in word:
return True
return False
@h2rashee
h2rashee / Sorting.java
Last active August 29, 2015 14:09
Simple sorting algorithms for ascending order
import java.util.*;
class Sort {
// Bubble Sort algorithm
void bubblesort(int[] arr) {
for(int i = arr.length - 1; i >= 0; i--) {
boolean noSwaps = true;
for(int j = 0; j < i; j++) {
@h2rashee
h2rashee / Bit.java
Created November 20, 2014 17:06
Bit Counting
import java.util.*;
class Bit {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
System.out.println("Bit representation: " + printBits(num));
System.out.println("Number of 1s: " + countBits(num));
}
@h2rashee
h2rashee / spaceRemove.py
Created November 20, 2014 19:02
Remove any spaces in a supplied input string
inp = raw_input('Input: ')
print inp.replace(" ", "")
@h2rashee
h2rashee / Adder.java
Last active August 29, 2015 14:10
Arithmetic with string numbers
/*
String s = add("1234","567");
1234
567
----
1801
=> "1801"
*/
@h2rashee
h2rashee / DirectoryMap.java
Last active August 29, 2015 14:10
Use absolute and relative path to get the resulting path
/*
Write a function (in a non-scripting language) to give the absolute path
given the current working directory and a path. e.g.
CWD: “/home/h2rashee/downloads/”
path: “../../hello.c”
result: “/home/hello.c”
CWD: “”
path: “../hello.c”
result: “../hello.c”
@h2rashee
h2rashee / Telecomm.java
Last active August 29, 2015 14:10
Google Phone Number Assignment
/*
Phone numbers are assigned to all the customers (in Canada, where
the phone number format is xxx xxx xxxx). We have three functions to do:
* isTaken? : is this number taken?
* iGaveOut : takes a number and marks it as taken.
* giveMeNumber : takes no arguments and returns a random number not taken.
Describe a data structure that can accomplish these functions
in the fastest possible time.
@h2rashee
h2rashee / LinkedLists.java
Created December 7, 2014 04:51
LinkedList ADT
class LinkedLists
{
public static void main(String[] args) {
LinkedList llist = new LinkedList();
// Use LinkedLIst class API here
}
}
class LinkedList