Skip to content

Instantly share code, notes, and snippets.

Adam Lum adamlum

Block or report user

Report or block adamlum

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@adamlum
adamlum / CodingInterviewPractice_2013_01_02.cs
Created Jan 5, 2013
Implement a simple singly-linked list data structure. Write a function to remove a list's 3rd from last element. (Challenge: can you do it in a single list traversal?) Write a function to remove all duplicates from a linked list. (Challenge: can you do it without storing any extra data?) Write a function to detect a loop in a linked list.
View CodingInterviewPractice_2013_01_02.cs
/****************************************************************
Adam Lum
01/05/2013
Coding for Interviews on Linked Lists
http://codingforinterviews.com
Implement a simple singly-linked list data structure.
Write a function to remove a list's 3rd from last element.
@adamlum
adamlum / CodingInterviewPractice_2012_12_24.cs
Created Dec 28, 2012
Write a function that merges an array of already sorted arrays, producing one large, still sorted array. (included a C# integer array merge sort method)
View CodingInterviewPractice_2012_12_24.cs
/****************************************************************
Adam Lum
12/28/2012
Coding for Interviews on Merge Sort
http://codingforinterviews.com
Write a function that merges an array of already sorted arrays,
producing one large, still sorted array.
@adamlum
adamlum / CodingInterviewPractice_2012_12_17.cs
Last active Dec 9, 2015
Write a function that returns whether a given binary tree is a valid binary search tree.
View CodingInterviewPractice_2012_12_17.cs
/****************************************************************
Adam Lum
12/17/2012
Coding for Interviews on Binary Search Trees
http://codingforinterviews.com
Write a function that returns whether a given binary tree
is a valid binary search tree.
@adamlum
adamlum / transformer.rb
Created Mar 7, 2011
Adam Lum's solution to RPCFN #8 (XML Transformer)
View transformer.rb
# Adam Lum's solution to RPCFN #8
# http://rubylearning.com/blog/2010/04/07/rpcfn-xml-transformer-8/
require 'rubygems'
require 'hpricot'
require 'rexml/document'
include REXML
# Get the source file(s) via the command line argument, didn't see anything
# in the challenge instructions detailing this step.
@adamlum
adamlum / fair_distribution.rb
Created Mar 7, 2011
Adam Lum's solution to RPCFN #6 (Fair Distribution)
View fair_distribution.rb
# Adam Lum's solution to RPCFN #6
# http://rubylearning.com/blog/2010/01/26/rpcfn-fair-distribution-6/
# Definitely not the most elegant, efficient, or Computer Science-y
# way to handle this challenge, but it's _a_ solution to these small sets.
# (For the sake of my code, hopefully the hypothetical t-shirt printing
# company in the problem never owns more than 4 machines) :)
class FairDistribution
@adamlum
adamlum / maze.rb
Created Jan 23, 2010
Adam Lum's solution to RPCFN #5 (Mazes)
View maze.rb
# Adam Lum's solution to RPCFN #5
# http://rubylearning.com/blog/2009/12/27/rpcfn-mazes-5/
class Maze
attr_accessor :maze_array, :start_point, :end_point
def initialize(in_maze)
@start_point = []
@end_point = []
@maze_array = in_maze.split("\n")
(0..@maze_array.size - 1).each do |i|
@adamlum
adamlum / polynomial.rb
Created Jan 23, 2010
Adam Lum's solution to RPCFN #4 (Ruby**Fun)
View polynomial.rb
# Adam Lum's solution to RPCFN #4
# http://rubylearning.com/blog/2009/11/26/rpcfn-rubyfun-4/
class Polynomial
attr_accessor :coefficient_array
def initialize(in_coefficient_array)
if (in_coefficient_array.size < 2)
raise ArgumentError, "Need at least 2 coefficients."
end
@coefficient_array = in_coefficient_array
@adamlum
adamlum / short_circuit.rb
Created Jan 22, 2010
Adam Lum's solution for RPCFN #3 (Short Circuit)
View short_circuit.rb
# Adam Lum's solution for RPCFN #3
# http://rubylearning.com/blog/2009/10/30/rpcfn-short-circuit-3/
INFINITY = 1 << 64
def dijkstra (graph, start, destination)
# Initialize
nodes = []
graph.each do |c|
nodes << c[0]
@adamlum
adamlum / average_time_of_day.rb
Created Jan 22, 2010
Adam Lum's solution to RPCFN #2 (Average Arrival Time for a Flight)
View average_time_of_day.rb
# Adam Lum's solution to RPCFN #2
# http://rubylearning.com/blog/2009/10/08/rpcfn-average-arrival-time-for-a-flight-2/
require 'time'
SECONDS_TO_CHECK_FOR = 10800 # Assuming 3 hours is a decent difference check
SECONDS_IN_DAY = 86400
def average_time_of_day(times)
count_greater = 0
@adamlum
adamlum / shift_subtitle.rb
Created Jan 21, 2010
Adam Lum's solution for RPCFN #1 (Shift Subtitle)
View shift_subtitle.rb
# Adam Lum's solution for RPCFN #1
# http://rubylearning.com/blog/2009/09/24/rpcfn-shift-subtitle-1/
require 'optparse'
# Get the command line arguments
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: shift_subtitle.rb [options] input_file output_file"
opts.on("--operation [OPERATION]") do |o|
You can’t perform that action at this time.