Epic Systems Interview Question for Software Developers


Country: United States
Interview Type: Written Test




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

could you give more information?

- Anonymous March 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can you define a sprint order matrix?

- HardCode March 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am sorry for the typo. I meant print out the spiral order matrix.

- joe sturridge March 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

He means just spiral order, not matrix. So starting from upper left, print in a spiral, moving inward. If you look at the output to my program it should make sense.

void PrintSpiral(int* matrix, int w, int h)
{
   int x = -1, y = 0, curLayers = 0;
   while (1)
   {
      if (x++ == w - curLayers)
         break;
      for (; x < w - curLayers; x++)
         printf("%d, ", matrix[y*w + x]);
      x--;

      if (y++ == h - curLayers)
         break;
      for (; y < h - curLayers; y++)
         printf("%d, ", matrix[y*w + x]);
      y--;

      if (x-- == curLayers)
         break;
      for (; x >= curLayers; x--)
         printf("%d, ", matrix[y*w + x]);
      x++;

      if (y-- == ++curLayers)
         break;
      for (; y >= curLayers; y--)
         printf("%d, ", matrix[y*w + x]);
      y++;
   }
}

void main()
{
   int mat[] = {1, 9, 21, 13,
                3, 7, 8,  -1, 
               13, 5, 2,   1, 
                5,-7, 3,  6};
   PrintSpiral(mat, 4, 4);
   getch();
}

Output:

1, 9, 21, 13, -1, 1, 6, 3, -7, 5, 13, 3, 7, 8, 2, 5,

- tjcbs2 March 06, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Spiralprint {

public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] multi = new int[][]{
{ 1, 2, 3, 4},
{ 12, 13, 14, 5},
{ 11, 16, 15, 6},
{ 10, 9, 8, 7}
};
printSpiral(multi);
}
public static void printSpiral(int[][] arr)
{
int x = arr.length;
int y = arr[0].length;
int currminrow = 0,currmaxrow = x-1;
int currmincol = 0,currmaxcol = y-1;
int i;
int count=x*y;
while(count>0)
{

for(i=currminrow;i<=currmaxcol;i++)
{
count --;
System.out.print(arr[currminrow][i]+" ");
}
for(i=currminrow+1;i<=currmaxrow;i++)
{
count --;
System.out.print(arr[i][currmaxcol]+ " ");
}
for(i=currmaxcol-1;i>=currmincol;i--)
{
count --;
System.out.print(arr[currmaxrow][i]+ " ");
}
for(i=currmaxrow-1;i>currminrow;i--)
{
count --;
System.out.print(arr[i][currmincol]+ " ");
}
currminrow++;
currmincol++;
currmaxcol--;
currmaxrow--;

}
}
}

- Sprial print - JAVA code (Tested) March 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Spiralprint {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[][] multi = new int[][]{
				  { 1, 2, 3, 4},
				  { 12, 13, 14, 5},	
				  { 11, 16, 15, 6},
				  { 10, 9, 8, 7}
				};
		printSpiral(multi);
	}
	public static void printSpiral(int[][] arr)
	{
		int x = arr.length;
		int y = arr[0].length;
		int currminrow = 0,currmaxrow = x-1;
		int currmincol = 0,currmaxcol = y-1;
		int i;
		int count=x*y;
		while(count>0)
		{
			
			for(i=currminrow;i<=currmaxcol;i++)
			{
				count --;
				System.out.print(arr[currminrow][i]+" ");
			}
			for(i=currminrow+1;i<=currmaxrow;i++)
			{
				count --;
				System.out.print(arr[i][currmaxcol]+ " ");
			}
			for(i=currmaxcol-1;i>=currmincol;i--)
			{
				count --;
				System.out.print(arr[currmaxrow][i]+ " ");
			}
			for(i=currmaxrow-1;i>currminrow;i--)
			{
				count --;
				System.out.print(arr[i][currmincol]+ " ");
			}
			currminrow++;
			currmincol++;
			currmaxcol--;
			currmaxrow--;
			
		}
	}
}

- Sprial Print - JAVA code(Tested) March 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void printSpiral(int[][] arr,int i,int j , int n ,int m){
        if (i > n || j > m) return;
        if (i == n || j == m ) {
            System.out.print(arr[i][j]);
            return;
        }

        for (int k = j ; k <= m ; k ++){
            System.out.print(arr[i][k]+ ",");
        }
        for (int l = i + 1; l <= n ; l ++){
            System.out.print(arr[l][m] + ",");
        }
        for (int e = m-1 ; e >= j ; e--){
            System.out.print(arr[n][e]+ ",");
        }
        for (int f = n-1; f > i ; f-- ){
            System.out.print(arr[f][j]+ ",");
        }
        printSpiral(arr,i+1 ,j+1, n-1, m-1);
    }

    public static void main(String[] args){
        int[][] arr = {{1, 9, 21, 13},
                {3, 7, 8,  -1},
                {13, 5, 2,   1},
                {5,-7, 3,  6}};
        printSpiral(arr,0,0,3,3);
        //1,9,21,13,-1,1,6,3,-7,5,13,3,7,8,2,5

}

- Anonymous March 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This does not work when m and n are not equal.

- anonymous September 11, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

does not work for m!=n

- abc September 11, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void printSpiral(int[][] arr,int i,int j , int n ,int m){
        if (i > n || j > m) return;
        if (i == n || j == m ) {
            System.out.print(arr[i][j]);
            return;
        }

        for (int k = j ; k <= m ; k ++){
            System.out.print(arr[i][k]+ ",");
        }
        for (int l = i + 1; l <= n ; l ++){
            System.out.print(arr[l][m] + ",");
        }
        for (int e = m-1 ; e >= j ; e--){
            System.out.print(arr[n][e]+ ",");
        }
        for (int f = n-1; f > i ; f-- ){
            System.out.print(arr[f][j]+ ",");
        }
        printSpiral(arr,i+1 ,j+1, n-1, m-1);
    }

    public static void main(String[] args){
        int[][] arr = {{1, 9, 21, 13},
                {3, 7, 8,  -1},
                {13, 5, 2,   1},
                {5,-7, 3,  6}};
        printSpiral(arr,0,0,3,3);
        //1,9,21,13,-1,1,6,3,-7,5,13,3,7,8,2,5
    }

- Kemo March 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a = [

[1,2,3,4,5],
    [6,7,8,9,10],
    [11,12,13,14,15],
    [16,17,18,19,20],
    [21,22,23,24,25]
    ]

row_start = 0
col_start = 0
row_length = len(a)-1
col_length = len(a)-1

while(row_start<= row_length):

i = row_start
    j = col_start
    while(i<row_length or j <=col_length):
        if j <=col_length:
            print(a[i][j], end = ", ")
            j +=1
        else:
            i +=1
            print(a[i][j-1], end = ", ")

    j -=1
    while(i>row_start+1 or j >col_start):
        if j >col_start:
            j -=1
            print(a[i][j], end = ", ")
        else:
            i -=1
            print(a[i][j], end = ", ")

row_start += 1
col_start +=1
row_length -=1
col_length -=1

- SB March 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SprialMatrix {

	public static void main(String[] args) {
		int[][] arr = new int[][] { { 1, 2, 3, 4 }, { 12, 13, 14, 5 },
				{ 11, 16, 15, 6 }, { 10, 9, 8, 7 } };

		for(int layer = 0; layer < arr.length/2; layer++) {
			
			for(int t = layer; t < arr.length - layer - 1; t++) {
				System.out.print(arr[layer][t] + " ");
			}
			for(int r = layer; r < arr.length - layer - 1; r++) {
				System.out.print(arr[r][arr.length - layer - 1] + " ");
			}
			for(int b = arr.length - layer - 1; b > layer; b--) {
				System.out.print(arr[arr.length - layer - 1][b] + " ");
			}
			for(int l = arr.length - layer - 1; l > layer; l--) {
				System.out.print(arr[l][layer] + " ");
			}
		}
	}

}

- Chinni April 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SprialMatrix {

	public static void main(String[] args) {
		int[][] arr = new int[][] { { 1, 2, 3, 4 }, { 12, 13, 14, 5 },
				{ 11, 16, 15, 6 }, { 10, 9, 8, 7 } };

		for(int layer = 0; layer < arr.length/2; layer++) {
			
			for(int t = layer; t < arr.length - layer - 1; t++) {
				System.out.print(arr[layer][t] + " ");
			}
			for(int r = layer; r < arr.length - layer - 1; r++) {
				System.out.print(arr[r][arr.length - layer - 1] + " ");
			}
			for(int b = arr.length - layer - 1; b > layer; b--) {
				System.out.print(arr[arr.length - layer - 1][b] + " ");
			}
			for(int l = arr.length - layer - 1; l > layer; l--) {
				System.out.print(arr[l][layer] + " ");
			}
		}
	}
}

Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

- Chinni April 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class P21 {

	private static void printSpircal(char[][] matrix) {
		int n = matrix.length;
		for (int r = 0; r <= n / 2; r++) {
			for (int j = r; j < n - r; j++) {
				System.out.print(matrix[r][j] + " ");
			}

			for (int j = r + 1; j < n - r; j++) {
				System.out.print(matrix[j][n - r - 1] + " ");
			}

			for (int j = n - r - 2; j >= r; j--) {
				System.out.print(matrix[n - r - 1][j] + " ");
			}

			for (int j = n - r - 2; j > r; j--) {
				System.out.print(matrix[j][r] + " ");
			}
		}
		System.out.println();
	}

	public static void main(String[] args) {
		char[][] matrix = { { 'a', 'b', 'c', '1' }, { 'd', 'e', 'f', '2' },
				{ 'g', 'h', 'k', '3' }, { '4', '5', '6', '7' } };
		printSpircal(matrix);
	}
}

- eng.mohamed.CSD2014 July 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SpiralMatrixPrint {

public static List<Integer> printSpiral(int[][] matrix) {

int rowBegin = 0;
int rowEnd = matrix.length - 1;
int colBegin = 0;
int colEnd = matrix[0].length - 1;

List<Integer> result = new ArrayList<Integer>();

while (rowBegin <= rowEnd && colBegin <= colEnd) {

for (int j = colBegin; j <= colEnd; j++) {

result.add(matrix[rowBegin][j]);
}
rowBegin++;

for (int i = rowBegin; i <= rowEnd; i++) {

result.add(matrix[i][colEnd]);

}

colEnd--;

if (rowBegin <= rowEnd) {

for (int j = colEnd; j >= colBegin; j--) {

result.add(matrix[rowEnd][j]);
}



}
rowEnd--;

if (colBegin <= colEnd) {

for (int i = rowEnd; i >= rowBegin; i--) {

result.add(matrix[i][colBegin]);
}

}
colBegin++;

}

return result;

}

public static void main(String args[]) {

// 1 2 3 4
// 5 6 7 8
// 9 10 11 12
// 13,14,15,16

// 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10

int[][] matrix = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } };

System.out.println(printSpiral(matrix));
}

}

- Naveen August 22, 2018 | 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