Skip to content

Instantly share code, notes, and snippets.

@WOLOHAHA
WOLOHAHA / CC150-9.8.java
Created August 11, 2014 14:00
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 of representing n cents.
package POJ;
public class Main {
/**
*
* 9.8 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 of representing n cents.
*
@WOLOHAHA
WOLOHAHA / CC150-9.7.java
Created August 11, 2014 11:40
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.
package POJ;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Main {
/**
*
@WOLOHAHA
WOLOHAHA / CC150-9.6.java
Created August 11, 2014 04:23
Implement an algorithm to print all valid combinations of n-pairs of parentheses.
package POJ;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Main {
/**
*
@WOLOHAHA
WOLOHAHA / CC150-9.4.java
Created August 8, 2014 08:49
Write a method to return all subsets of a set.
package POJ;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main{
/**
*
@WOLOHAHA
WOLOHAHA / CC150-9.3.java
Last active June 27, 2018 00:53
A magic index in an array A[1.. .n-1] is defined to be an index such that A =i. Given a sorted array of distinct integers, write a method to find a magic index, if one exists, in array A.
package POJ;
public class Main{
/**
*
* 9.3 A magic index in an array A[1.. .n-1] is defined to be an index such that A =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?
@WOLOHAHA
WOLOHAHA / CC150-9.2-Followup.java
Last active August 29, 2015 14:05
Imagine a robot sitting on the upper left comer of an X by Ygrid. 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 algorithm to find a path for the robot from…
package POJ;
public class Main{
/**
*
* Now consider if some obstacles are added to the grids. How many unique paths would there be?
* An obstacle and empty space is marked as 1 and 0 respectively in the grid.
*
*
@WOLOHAHA
WOLOHAHA / CC150-9.1.java
Created August 8, 2014 04:27
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 possible ways the child can run up the stairs.
package POJ;
public class Main{
/**
*
* 9.1 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 possible ways the child can run up the stairs.
*
*
@WOLOHAHA
WOLOHAHA / CC150-7.7.java
Last active August 29, 2015 14:04
Design an algorithm to find the kth number such that the only prime factors are 3,5,and 7.
package POJ;
import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
public class Main{
@WOLOHAHA
WOLOHAHA / CC150-7.6.java
Created August 4, 2014 16:04
Given a two-dimensional graph with points on it, find a line which passes the most number of points.
package POJ;
import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;
public class Main{
/**
*
@WOLOHAHA
WOLOHAHA / CC150-7.4.java
Created August 4, 2014 07:35
Write methods to implement the multiply, subtract and divide operations for integers. Use only the add operator.
package POJ;
import java.util.ArrayList;
public class Main{
/**
*
* 7.4 Write methods to implement the multiply, subtract and divide operations for integers. Use only the add operator.
*