Skip to content

Instantly share code, notes, and snippets.

View stphung's full-sized avatar

Steven Phung stphung

  • Autodesk, Inc.
  • San Francisco, CA
View GitHub Profile
@stphung
stphung / ToastXToast.java
Created April 16, 2011 18:07
TopCoder SRM 503 Division 2 - 500 point problem
import java.util.Arrays;
public class ToastXToast {
public int bake(int[] undertoasted, int[] overtoasted) {
Arrays.sort(undertoasted);
Arrays.sort(overtoasted);
if (undertoasted[0] > overtoasted[0] || undertoasted[undertoasted.length - 1] > overtoasted[overtoasted.length - 1]) {
return -1;
} else if (undertoasted[undertoasted.length - 1] < overtoasted[0]) {
/*
ID: stphung1
LANG: JAVA
TASK: milk
*/
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
/*
ID: stphung1
LANG: JAVA
TASK: dualpal
*/
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
/*
ID: stphung1
LANG: JAVA
TASK: barn1
*/
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
@stphung
stphung / ComparerInator.java
Created April 26, 2011 16:31
TopCoder SRM 504 Division 2 - 250 point problem
import java.util.Arrays;
public class ComparerInator {
public int makeProgram(int[] A, int[] B, int[] wanted) {
if (same(A, wanted))
return 1;
else if (same(B, wanted))
return 1;
else if (ltTest1(A, B, wanted))
@stphung
stphung / MathContest.java
Created April 26, 2011 16:31
TopCoder SRM 504 Division 2 - 500 point problem
import java.util.Stack;
public class MathContest {
public int countBlack(String ballSequence, int repetitions) {
String newBallSequence = ballSequence;
Stack<Integer> stack = new Stack<Integer>();
for (int i = newBallSequence.length() - 1; i >= 0; i--) {
if (newBallSequence.charAt(i) == 'B')
@stphung
stphung / PerfectSequences.java
Created May 3, 2011 12:42
TopCoder SRM 505 Division 2 - 500 point problem
public class PerfectSequences {
public String fixIt(int[] seq) {
if (seq.length == 1) return "Yes";
else {
for(int i=0; i<seq.length; i++) {
int sum = sum(seq,i);
int product = product(seq,i);
if (product == 0) continue;
else {
@stphung
stphung / BotTrust.java
Created May 8, 2011 18:16
Google Code Jam 2011 Qualifier Round - Problem A, Bot Trust
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.LinkedBlockingQueue;
public class BotTrust {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("A-large.in"));
@stphung
stphung / Magicka.java
Created May 8, 2011 18:23
Google Code Jam 2011 Qualifier Round - Problem B, Magicka
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
@stphung
stphung / CandySplitting.java
Created May 8, 2011 19:17
Google Code Jam 2011 Qualifier Round - Problem C, Candy Splitting
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class CandySplitting {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("C-small-attempt0.in"));