Skip to content

Instantly share code, notes, and snippets.

@kolauren
kolauren / gist:4719071
Created February 6, 2013 00:19
Coding for Interviews: Stack 1
# Not really a "use-case" per se, but I always thought this problem was
# interesting because it has a really simple answer (as you can see below).
# Sometimes it is asked in coding interviews.
#
# How do you implement a Queue using only Stack data structure?
class Node:
def __init__(self, item, next):
self.item = item
self.next = next
@kolauren
kolauren / stack.py
Created February 6, 2013 00:00
Coding for Interviews: Stack 2
# A simple stack, LIFO fo' lyfe
class Node:
def __init__(self, item, next):
self.item = item
self.next = next
class Stack:
top = None
@kolauren
kolauren / heap
Created January 30, 2013 06:19
Simple heap with heapsort
// Heapsort with Java
// Heap properties:
// Left child of h[i] is h[2i + 1] (given 2i + 1 < h.size)
// Right child of h[i] is h[2i + 2] (given 2i + 2 < h.size)
// parent of h[i] is h[(i-1)/2] (given i > 0)
public class Heap {
int[] heap;
int size;
@kolauren
kolauren / Reversing a linked list
Last active March 30, 2023 13:17
Reversing a linked list
// Reverse a linked list
public class Test {
public static class Node {
public int value;
public Node next;
public Node(int value, Node next) {
this.value = value;
this.next = next;
}
@kolauren
kolauren / find unique value
Created January 29, 2013 23:33
interview practice
import java.util.*;
public class Test {
// You are given an array with n positive integers where all values in the array are repeated except for one.
// Return the one that is not repeated.
// brute force answer
public static int notRepeated_bf(int[] integers) {
int not_repeated;
int current_num;
1. Explain what the big three depth-first tree traversals are and what to consider when implementing them.
The big three depth-first tree traversals are ways to traverse a tree. "Depth-first" means that they will traverse to the lowest depth before moving on to the next node. The three ways are inorder (left, root, right), preorder (root, left, right) and postorder (left, right, root).