Cloudera Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

You are doing extra work for repeated rows and/or columns.

void force_zero(int m, int n, int** matrix, int k, int* x, int* y)
{
	bool* row_flag = new bool[m];
	bool* col_flag = new bool[n];
	
	fill_n(row_flag, m, false);
	fill_n(col_flag, n, false);
	
	for(int i=0; i<k; i++)
	{
		row_flag[x[i]]=true;
		col_flag[y[i]]=true;
	}
	
	for(int i=0; i<m; i++)
		if(row_flag[i])
			fill_n(matrix[i], n, 0);
	
	for(int i=0; i < n; i++)
		for(int j=0; col_flag[i] && j < m; j++)		
			matrix[j][i]=0;
	
	delete [] row_flag;
	delete [] col_flag;
}

- lasthope November 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Right. Extra work can be avoided.

- Anonymous November 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just upvote our gods. One of them will end up posting right answers.

- {lasthope, =, subbu, Anonymous} is my god November 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What troubles you, my child?

- Anonymous God. November 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just upvote our gods. One of them will end up posting right answers.

- {lasthope, =, subbu, Anonymous} is my god November 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What I said.

- Schizophrenic God November 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Solution {
    public void setZeroes(int[][] matrix) {
        HashMap<Integer,Boolean> row = new HashMap<Integer,Boolean>();
        HashMap<Integer,Boolean> col = new HashMap<Integer,Boolean>();
        LinkedList<int []> pts = new LinkedList<int[]>();
        for (int c = 0; c < matrix.length; c++){
            for (int r = 0; r < matrix[c].length;r++){
                if(matrix[c][r] == 0){
                    pts.add(new int[]{c,r});
                }
            }
        }
        
        for(int [] pt : pts){
            if(!row.containsKey(pt[1])){
                row.put(pt[1],true);
                for (int i = 0; i < matrix.length;i++){
                    matrix[i][pt[1]] = 0;
                }
            }
            if(!col.containsKey(pt[0])){
                col.put(pt[0],true);
                for (int i = 0; i < matrix[0].length;i++){
                    matrix[pt[0]][i] = 0;
                }
            }
        }
 
    }
}

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

maybe I'm missing something but this seems really easy in Python -


def mat(alist, xylist):
for (x,y) in (xylist):
alist[x][y] = 0
return alist

- addybist December 03, 2014 | 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