Oracle Interview Question for Senior Software Development Engineers


Country: India
Interview Type: In-Person




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

public static void printMatrixSpiral(char[][] matrix){
		int numRows = matrix.length;
		int numColumns = matrix[0].length;
		int totalNodes = numRows*numColumns;
		int nodesVisted = 0;
		int startRow =0;
		int startColumn = 0;
		while (nodesVisted < totalNodes){
			int column =startColumn;
			while (column<numColumns-1){
				System.out.print(matrix[startRow][column]);
				column++;
				nodesVisted++;
			}
			int row =startRow;
			while (row<numRows-1){
				System.out.print(matrix[row][column]);
				row++;
				nodesVisted++;
			}
			while (column>startColumn){
				System.out.print(matrix[row][column]);
				column--;
				nodesVisted++;
			}
			while (row>=startRow){
				System.out.print(matrix[row][column]);
				row--;
				nodesVisted++;
			}
			startRow++;
			startColumn++;
			numColumns--;
			numRows--;
		}
	}

- cvishwakarma July 18, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Main{
static void spiralPrint(int m, int n, int a[][]) {
int i, k = 0, l = 0;
/* k - starting row index
m - ending row index
l - starting column index
n - ending column index
i - iterator
*/
while (k < m && l < n) {
for (i = l; i < n; ++i) {
System.out.print(a[k][i]+" ");
}
k++;
for (i = k; i < m; ++i) {
System.out.print(a[i][n-1]+" ");
}
n--;
if ( k < m) {
for (i = n-1; i >= l; --i) {
System.out.print(a[m-1][i]+" ");
}
m--;
}
if (l < n) {
for (i = m-1; i >= k; --i) {
System.out.print(a[i][l]+" ");
}
l++;
}
}
}
public static void main (String[] args) {
int R = 3;
int C = 6;
int a[][] = { {1, 2, 3, 4, 5, 6},
{7, 8, 9, 10, 11, 12},
{13, 14, 15, 16, 17, 18}
};
spiralPrint(R,C,a);
}
}

- preety.bit36 July 28, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Demo {
	
	public static void main(String args[]) {
		char[][] matrix = {{'a','b','c','d'},{'e','f','g','h'},{'i','j','k','l'},{'m','n','o','p'}};
		
		int rowLen=matrix.length;
		int colLen=matrix[0].length;
		int mod=0;
		int start=0;
		int end=colLen;
		int incr=1;
		for(int r=0;r<rowLen;r++) {
			mod=r%2;
			if(mod!=0) {
				start=colLen-1;
				end=0-1;
				incr=-1;
			}
			else{
				start=0;
				end=colLen;
				incr=1;
			}
			for(int j=start;mod==0?j<end:j>end;j=j+incr) {
				System.out.println(matrix[r][j]);
			}
		}
		
	}
}

- jaison September 09, 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