Epic Systems Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
1
of 1 vote

Naive Java implementation:

public class TicTacToe {
	private int fieldSize;
	private int[] rowCounter = new int[3];
	private int[] colCounter = new int[3];
	private int[] diagCounter = new int[2];
	private boolean[][] checkMark = new boolean[3][3];
	public TicTacToe(int fieldSize){
		if (fieldSize < 3){
			this.fieldSize = 3;public class TicTacToe {
	private int fieldSize;
	private int[] rowCounter = new int[3];
	private int[] colCounter = new int[3];
	private int[] diagCounter = new int[2];
	private boolean[][] checkMark = new boolean[3][3];
	public TicTacToe(int fieldSize){
		if (fieldSize < 3){
			this.fieldSize = 3;
		} else {
			this.fieldSize = fieldSize;
		}
		this.rowCounter = new int[this.fieldSize];
		this.colCounter = new int[this.fieldSize];
		this.checkMark = new boolean[this.fieldSize][this.fieldSize]; 
		for (int i=0; i<this.fieldSize; ++i){
			this.rowCounter[i] = 0;
			this.colCounter[i] = 0;
		}
	}

	private TicTacToe(){}

	/** place mark function, (x, y) pins the position and 'player' should be either -1 or 1
	 * 
	 * @param x
	 * @param y
	 * @param player
	 * @return 1: 1p wins, 2: 2p wins, -1: x | y out of bounds; 0: just another day at the office
	 */
	public int placeMark(int x, int y, int player){
		if((x>fieldSize && x<0) || (y>fieldSize && y<0)){
			return -1;
		}
		if(!(player == -1 || player == 1)){
			return -1;
		}
		if(this.checkMark[x][y]){
			return -1;
		} else {
			this.checkMark[x][y] = true;
		}
		
		this.rowCounter[x] += player;
		if(isWin(this.rowCounter, x)!=0){return isWin(this.rowCounter, x);}
		this.colCounter[y] += player;
		if(isWin(this.colCounter, y)!=0){return isWin(this.colCounter, y);}
		
		if(x==y){
			this.diagCounter[0] += player;
			if(isWin(this.diagCounter, 0)!=0){return isWin(this.diagCounter, 0);}
			this.diagCounter[1] += player;
			if(isWin(this.diagCounter, 1)!=0){return isWin(this.diagCounter, 1);}
		} else {
			if(x+y==this.fieldSize+1){
				this.diagCounter[1] += player;
				if(isWin(this.diagCounter, 1)!=0){return isWin(this.diagCounter, 1);}
			}
		}
		return 0;
	}
	
	private int isWin(int[] counter, int index){
		if (Math.abs(counter[index])==this.fieldSize){
			if (counter[index] < 0) {return 1;} else {return 2;} 
		}
		return 0;
	}
}
		} else {
			this.fieldSize = fieldSize;
		}
		this.rowCounter = new int[this.fieldSize];
		this.colCounter = new int[this.fieldSize];
		this.checkMark = new boolean[this.fieldSize][this.fieldSize]; 
		for (int i=0; i<this.fieldSize; ++i){
			this.rowCounter[i] = 0;
			this.colCounter[i] = 0;
		}
	}

	private TicTacToe(){}

	/** place mark function, (x, y) pins the position and 'player' should be either -1 or 1
	 * 
	 * @param x
	 * @param y
	 * @param player
	 * @return 1: 1p wins, 2: 2p wins, -1: x | y out of bounds; 0: just another day at the office
	 */
	public int placeMark(int x, int y, int player){
		if((x>fieldSize && x<0) || (y>fieldSize && y<0)){
			return -1;
		}
		if(!(player == -1 || player == 1)){
			return -1;
		}
		if(this.checkMark[x][y]){
			return -1;
		} else {
			this.checkMark[x][y] = true;
		}
		
		this.rowCounter[x] += player;
		if(isWin(this.rowCounter, x)!=0){return isWin(this.rowCounter, x);}
		this.colCounter[y] += player;
		if(isWin(this.colCounter, y)!=0){return isWin(this.colCounter, y);}
		
		if(x==y){
			this.diagCounter[0] += player;
			if(isWin(this.diagCounter, 0)!=0){return isWin(this.diagCounter, 0);}
			this.diagCounter[1] += player;
			if(isWin(this.diagCounter, 1)!=0){return isWin(this.diagCounter, 1);}
		} else {
			if(x+y==this.fieldSize+1){
				this.diagCounter[1] += player;
				if(isWin(this.diagCounter, 1)!=0){return isWin(this.diagCounter, 1);}
			}
		}
		return 0;
	}
	
	private int isWin(int[] counter, int index){
		if (Math.abs(counter[index])==this.fieldSize){
			if (counter[index] < 0) {return 1;} else {return 2;} 
		}
		return 0;
	}
}

- Suz February 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The following functions -

class TicTacToe
{
......
};

constructor- > should Initialize the board , register 2 players , assign X & O to them .
Start() --> Starts a Timer for Player whose move it is to make his move .
//should contain the logic for time Out .

IsGameOver() --> if anybody has won the game / Draw / Aborted .
IsADraw() , IsWon() etc .

Stop() -> should clean up all the resources .

Class Player
{
...
};

should contain functions like myTurn , hasWon etc .

Implementation -

The Board should be represented using bitboard i.e an array of 9 bits . This results in O(1) checking of various details .

- Anonymous January 14, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More