Skip to content

Instantly share code, notes, and snippets.

@bchetty
Created April 24, 2014 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bchetty/11250572 to your computer and use it in GitHub Desktop.
Save bchetty/11250572 to your computer and use it in GitHub Desktop.
GCJ 2014 - Magic Trick Problem
package com.bchetty.gcj2014;
import java.util.ArrayList;
import java.util.List;
/**
* GCJ 2014 - Magic Trick Problem
*
* @author Babji, Chetty
*/
public class MagicTrick {
/**
*
* @param firstRow
* @param rowList1
* @param secondRow
* @param rowList2
* @return
*/
public String findTrickResult(List<Integer> rowList1, List<Integer> rowList2) {
int count = 0;
int res = 0;
String result = null;
for(int i=0;i<rowList1.size();i++) {
int temp = rowList1.get(i);
if(rowList2.contains(temp)) {
count++;
res = temp;
}
}
switch(count) {
case 0:
result = "Volunteer cheated!";
break;
case 1:
result = "" + res;
break;
default:
result = "Bad magician!";
break;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment