Cloudera Interview Question for SDETs


Country: United States
Interview Type: Phone Interview




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

Run DFS with Queue and print layer by layer..

- naren December 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess you mean BFS.

- hiuhchan December 12, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Oh yes. Typo on my end.. Thanks for correcting this.

- naren December 12, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

push root to existingQueue;

do
{
Queue newQueue = new Queue();

while(existingQueue not Empty)
{
pop 'the element' from existingQueue;
print 'the element';
push all children of 'the element' to newQueue;
}
print newline;

existingQueue = newQueue;
}
while( existingQueue not empty);

- DigitalCasper December 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void print_tree(Tree tree)
{
    queue q;

    int lvl_size = 1;
    int next_lvl_size = 0;
    q.enqueue(tree);

    while (!q.empty()) {
        Tree t = q.pop();

        if (t.left) {
            next_lvl_size++;
            q.enqueue(t.left);
        }

        if (t.right) {
            next_lvl_size++;
            q.enqueue(t.right);
        }

        print(t);

        if (--lvl_size == 0) {
            print(NewLine);
            lvl_size = next_lvl_size;
            next_lvl_size = 0;
        }
    }
}

- rm December 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static class TreeNode{
	TreeNode left, right;
	char c;
}
public static void printTree(TreeNode node){
	if(node == null){
		return;
	}
	Queue<TreeNode> queue = new Queue<TreeNode>(1);
	Quere<TreeNode> tempQueue = new Queue<TreeNode>();
	queue.add(node);
	StringBuffer buffer = new StringBuffer();
	while(queue.size() > 0){
		buffer.setLength(0);	
		while(queue.peek() != null){
			TreeNode workingNode = queue.poll)(;
			TreeNode childNode = workingNode.left;
			if(childNode != null){
				tempQueue.add(childNode);
			}
			childNode = workingNode.right;
			if(childNode != null){
				tempQueue.add(childNode);
			}
			buffer.add(workingNode.c);
		}
		System.out.println(buffer.toString());
		Queue tempPointer = queue;
		queue = tempQueue;
		tempQueue = tempPointer;
	}
}

- zortlord December 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{void tree ::LevelorderTraver(Node* head)
{

queue<Node*> q;
Node* temp;


q.push(head);

int previous =1;
int index =1;
int x =0;


while(q.empty()!=1)
{

temp = q.front();
if(temp->left !=NULL){ q.push(temp->left); x++;};
if(temp->right !=NULL) {q.push(temp->right);x++;};


if(previous >=index){cout<< temp->data <<" "; index++;}
else
{
previous = x;
x=0;
index =1;
cout<<endl;

}


q.pop();

}

}
}

- satish.timiri December 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

hdjd

and

dssldkfn

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

public static void main() {

}

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

Not a sorting solution, but create a max heap out these elements and delete the root till three distinct values are fetched.

- Prasanna S September 03, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public List<List<Integer>> levelOrder(TreeNode root) {
List<List<Integer>> result = new ArrayList<>();
Queue<TreeNode> queue = new LinkedList<>();
if(root == null)
return result;
queue.add(root);
while(!queue.isEmpty()) {
int levelNodes = queue.size();
List<Integer> list = new ArrayList<>();
while(levelNodes > 0) {
TreeNode n = queue.poll();
list.add(n.val);
if(n.left != null)
queue.add(n.left);
if(n.right != null)
queue.add(n.right);
levelNodes--;
}
result.add(list);
}
return result;
}

- hivejin March 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* ZoomBA.
Level order traversal.
The key is to understand that, 
you need to maintain two queues, one for current,
another for next level.
After a level is exhausted, 
one needs to replace that queue by the one from built up  
*/

def level_order( root ){
  cur = list( root ) // current level 
  while ( !empty(cur) ){
    // get one and go along with it 
    node = cur.dequeue() 
    printf(' %s ', node.value ) // print it 
    next = list()
    for ( child : node.children ){
       next.enqueue( child ) // queue it 
    }
    println() // completes the level 
    cur = next // switch the level 
  }
}

- NoOne November 08, 2016 | 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