Ebay Interview Question for SDE-2s


Team: Traffic
Country: United States
Interview Type: In-Person




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

static void markZero(int[][][] m) {


int i,j,k;
//Put all the indices of matrix that contains zero in a hashmap
for(i=0; i<m.length; i++) {
for(j=0; j<m[0].length; j++) {
for(k=0; k<m[0][0].length; k++) {
if(m[i][j][k] == 0) {
System.out.println(m[i][j][k] + " i " + i + "j " + j + "k " + k);
sb4 = new StringBuffer(sb); sb5 = new StringBuffer(sb); sb6 = new StringBuffer(sb);
sb4 = sb4.append(i);
sb4 = sb4.append(j);
sb4 = sb4.append("X");
// System.out.println(sb4);

sb5 = sb5.append(i);
sb5 = sb5.append("X");
sb5 = sb5.append(k);
// System.out.println(sb5);

sb6 = sb6.append("X");
sb6 = sb6.append(j);
sb6 = sb6.append(k);
// System.out.println(sb6);

rcd.put(sb4.toString(), 1);
rcd.put(sb5.toString(), 1);
rcd.put(sb6.toString(), 1);

}
}
}
}
Iterator<Entry<String, Integer>> it = rcd.entrySet().iterator();
while (it.hasNext()) {
System.out.println(it.next());
}

for(i=0; i<m.length; i++) {
for(j=0; j<m[0].length; j++) {
for(k=0; k<m[0][0].length; k++) {
sb1 = new StringBuffer(sb); sb2 = new StringBuffer(sb); sb3 = new StringBuffer(sb);
sb1 = sb1.append(i);
sb1 = sb1.append(j);
sb1 = sb1.append("X");
// System.out.println(sb1);

sb2 = sb2.append(i);
sb2 = sb2.append("X");
sb2 = sb2.append(k);
// System.out.println(sb2);

sb3 = sb3.append("X");
sb3 = sb3.append(j);
sb3 = sb3.append(k);
// System.out.println(sb3);

if(rcd.containsKey(sb1.toString()) || rcd.containsKey(sb2.toString()) || rcd.containsKey(sb3.toString())) {
m[i][j][k] = 0;
// System.out.println(m[i][j][k]);
}
}
}
}
for(i=0; i<m.length; i++) {
for(j=0; j<m[0].length; j++) {
for(k=0; k<m[0][0].length; k++) {
System.out.println(m[i][j][k]);
}
}
}
}
}

- Anonymous April 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private void manipulate(int[][][] matrixArray) {
boolean[] x= new boolean[matrixArray.length];
boolean[] y= new boolean[matrixArray[0].length];
boolean[] z= new boolean[matrixArray[0][0].length];
for (int i = 0; i < x.length; i++) {
for (int j = 0; j < y.length; j++) {
for(int k = 0; k< z.length; k++){
if (matrixArray[i][j][k] == 0) {
x[i] = true;
y[j] = true;
z[k] = true;
break;
}
}
}
}
for (int i = 0; i < x.length; i++) {
for (int j = 0; j < y.length; j++) {
for (int k = 0; k < z.length;k++) {
if(x[i]||y[j]||z[k]){
matrixArray[i][j][k] = 0;
}

}
}
}
}

- sLion August 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Solution by @thelineofcode is correct. This is just a 3-D version of problem 1.7 from the book, Cracking the Coding interview.

- DevGuy January 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is not correct. If matrix[i][j][k] == 0, your algorithm will set

matrix[i][*][*]=0, matrix[*][j][*]=0 and matrix[*][*][k]=0

The question asks to set

matrix[i][j][*]=0, matrix[i][*][k]=0 and matrix[*][j][k]=0

- chriscow January 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You should use three matrix rather than three array to first time save the zero location.

- hejiacongtheone February 26, 2014 | Flag


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