Skip to content

Instantly share code, notes, and snippets.

View charlespunk's full-sized avatar

charlespunk charlespunk

View GitHub Profile
A child is running up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how
many posible ways the child can run up the stairs.
Imagine a robot sitting on the upper left corner of an X by Y grid. The robot can only move in two directions: right and down. How many
possible paths are there for the robot to go from (0, 0) to (X, Y)?
FOLLOW UP
Imagine certain spots are "off limits", such that the robot cannot step on them. Design an algotithm to find a path for the robot from the
top left to the bottom right.
A magic index in an array A[1 ... n-1] is defined to be an index such that A[i] = i. Given a sorted array of distinct integers, write a
method to find a magic index, if one exists, in array A.
FOLLOW UP
What if the values are not distinct.
Write a method to return all subsets of a set.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
public class SortHashMap {
Write a method to compute all permutations of a string.
Implement an algorithm to print all valid (i.e., properly opened and closed) combinations of n-pairs of parentheses.
Implement the "paint fill" function that one might see on many image editing programs. That is, Given a screen(represented by a two-dimensional
array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color.
Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies (1 cent), write code to calculate the number of ways representing n cents.
Write an alogrithm to print all ways of arranging eight queens on an 8*8 chess board so that none of them share the same row, colum or diagonal. In this case, "diagonal" means all diagonals, not just the two that bisect the board.