Skip to content

Instantly share code, notes, and snippets.

View h2rashee's full-sized avatar

Harris Rasheed h2rashee

View GitHub Profile
@h2rashee
h2rashee / Data.java
Last active August 29, 2015 14:11
Simple Database
import java.util.Hashtable;
import java.util.Stack;
class Data
{
// Stores <key>-<value> pairs
Hashtable<String, String> data;
// Stores <value>-<value quantity> pairs
Hashtable<String, Integer> valCount;
@h2rashee
h2rashee / emailSend.py
Created December 26, 2014 06:04
Simplistic script (somewhat) to send a Gmail E-mail
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import smtplib
def sendEmail(fromAdd, toAdd, body):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(True)
server.starttls()
@h2rashee
h2rashee / Sudoku.java
Last active August 29, 2015 14:12
Given a Sudoku board, determine whether it is valid or not
import java.io.*;
import java.util.*;
/*
+===+===+===+===+===+===+===+===+===+
‖ : : ‖ : : ‖ : : ‖
+---+---+---+---+---+---+---+---+---+
‖ : 1 : 2 ‖ : : ‖ 3 : : ‖
+---+---+---+---+---+---+---+---+---+
@h2rashee
h2rashee / Intersection.java
Last active August 29, 2015 14:12
Given two sorted arrays of integers, find the intersection
import java.util.*;
// Time complexity is the length of both arrays (linear)
class Intersection
{
ArrayList<Integer> results;
public static void main (String [] args)
{
@h2rashee
h2rashee / Average.java
Last active August 29, 2015 14:13
Collection optimised to get Averages
import java.io.*;
import java.util.*;
/*
* 1) O(1) memory usage
* 2) Numbers in range [0, 1000)
* 3) Definition of median:
* [1, 2, 3] = 2
* [1, 2, 3, 4] = 2.5
*/
@h2rashee
h2rashee / Solution.java
Last active August 29, 2015 14:13
Binary Tree Serialisation
import java.io.*;
import java.util.*;
class Node {
String val;
Node left;
Node right;
Node(String data) {
@h2rashee
h2rashee / FizzBuzz.java
Last active August 29, 2015 14:13
FizzBuzz (Typical Interview Question)
/*
* http://en.wikipedia.org/wiki/Fizz_buzz
*/
class FizzBuzz
{
public static void main (String [] args)
{
for(int i = 1; i <= 100; i++) {
if(i%3 == 0) {
@h2rashee
h2rashee / FizzBuzz.py
Created January 14, 2015 11:31
FizzBuzz (Typical Interview Question)
# http://en.wikipedia.org/wiki/Fizz_buzz
for i in range(1, 101):
if not i%3:
if not i%5:
print "FizzBuzz"
continue
print "Fizz"
elif not i%5:
print "Buzz"
@h2rashee
h2rashee / bfs.java
Last active August 29, 2015 14:15
Breadth-First Search in a Binary Tree
/*
1. Write Breadth-First Traversal on a Tree
1
2 3
4 5 6
2 2 3 --
1 2 3 4 5 6
@h2rashee
h2rashee / Palindrome.java
Created February 17, 2015 19:31
Find the longest palindrome substring
import java.io.*;
import java.util.*;
/*
* To execute Java, please define "static void main" on a class
* named Solution.
*
* If you need more classes, simply define them inline.
*/