Skip to content

Instantly share code, notes, and snippets.

View h2rashee's full-sized avatar

Harris Rasheed h2rashee

View GitHub Profile
@h2rashee
h2rashee / concordance.py
Created October 19, 2017 07:36
Given a string, find it's concordance
# Given an arbitrary text document written in English, write a program that will
# generate a concordance, i.e. an alphabetical list of all word occurrences,
# labeled with word frequencies.
#
# Bonus: label each word with the sentence numbers in which each occurrence appeared.
from nltk.tokenize import word_tokenize
import fileinput
import nltk
@h2rashee
h2rashee / hit_counts.py
Last active October 17, 2017 05:02
Given list of entries "hits, domain", determine the total hits of each subdomain
// Given a list of strings (int, string) where int is the number of hits and the string is a domain name,
// tally a domain and each of its subdomains' total hits.
hit_list = ["100,yahoo.com",
"20,mail.yahoo.com"]
def calculate_domain_hits():
domain_counts = {}
for entry in hit_list:
# Parse each input entry
@h2rashee
h2rashee / substring.py
Created October 11, 2017 09:12
Given a string, determine the length of the longest substring with no repeating characters
def find_len_substr(string):
start = 0
cur = start
cur_max = 0
seen = {}
while start < len(string):
deja_vu = False
for x in range(start, len(string)):
@h2rashee
h2rashee / numberSystem.java
Created August 15, 2016 06:56
Given a list of bases for individual digit positions, find all possible numbers in that system
// Given digits,
public void calculateNumberSystem(int[] bases) {
int[] num = new int[bases.length];
HashSet<String> nums = new HashSet<String>();
for(int i = bases.length-1; i >= 0; i--) {
// Add result to set
nums.add(Arrays.toString(num));
@h2rashee
h2rashee / CourseSuggestions.java
Created May 31, 2016 06:23
Given a graph of users, determine the best course suggestions to give the central user based on the spec
/*
* import java.util.*;
* import java.io.*;
*
* public List<String> getDirectFriendsForUser(String user)
*
* public List<String> getAttendedCoursesForUser(String user)
*
* Please complete the method below
@h2rashee
h2rashee / StockAnalysis.java
Last active February 29, 2016 08:09
Given a set of stock prices modelled over time, determine the best gain from buying and selling the stock.
import java.io.*;
import java.util.*;
class StockAnalysis {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for(int i = 0; i < n; i++) {
@h2rashee
h2rashee / TextDuplicator.java
Last active October 21, 2015 23:01
Given a sentence and a screen specification, find out how many duplications are possible without word breaks
/*
Given a text with N words (a_1 ... a_N), and a very large textual screen of
width C chars and height L lines (C & L may be much larger than N).
How many times would the text fully fit on the screen if words cannot be broken?
Text = "this is an example"
C = 15
L = 5
textOnScreen(text, c, l) = 3
@h2rashee
h2rashee / IntervalCheck.java
Last active December 13, 2015 21:14
Interval Problems
/*
Given a set of intervals, determine whether a number lies in any of those
ranges.
[1, 5], [7, 10]
Example:
5: True
11: False
@h2rashee
h2rashee / DoubleList.java
Last active October 11, 2015 05:43
Determine the symmetric difference of multiple lists of numbers
/*
Given a multiple sorted lists, determine the unique elements (symmetric difference).
https://en.wikipedia.org/wiki/Symmetric_difference
*/
import java.util.*;
class DoubleList
{
public static void main (String [] args)
@h2rashee
h2rashee / Multiply.java
Created October 11, 2015 01:01
Multiplication table
class Multiply
{
public static void main (String [] args)
{
int base = 12;
// List style
for(int i = 1; i <= base; i++) {
for(int j = 1; j <= base; j++) {
System.out.println(i + " x " + j + ": " + i*j);