iLabs Interview Question for Senior Software Development Engineers


Country: India
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
3
of 5 vote

Check in-order traversal is sorted or not

- ajit.virus.bit July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

private boolean isBST() {
        return isBST(root, null, null);
    }

  private boolean isBST(Node x, Key min, Key max) {
        if (x == null) return true;
        if (min != null && x.key.compareTo(min) <= 0) return false;
        if (max != null && x.key.compareTo(max) >= 0) return false;
        return isBST(x.left, min, x.key) && isBST(x.right, x.key, max);
    }

- no.1ankush July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is probably simple to don't check for a null everytime or any other flag but just provide the maximum and minimum numbers of the int.Max and int.Min

class Node 
{
	int data;
	Node left;
	Node right;
}

public bool IsBST(Node root)
{
	return IsBST(root, int.Max, int.Min);
}

private bool IsBSTCore(Node root, int min, int max)
{
	if(root == null)
	{
		return true;
	}

	// Assuming that values can be repeated on either right or left
	if(root.data < min || root.data > max)
	{
		return false;
	}
	
	return IsBST(root.left, min, root.data) && IsBST(result.right, root.data, max);
}

- Nelson Perez August 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

bool isBST(struct node* root)
{
static struct node *prev = NULL;

// traverse the tree in inorder fashion and keep track of prev node
if (root)
{
if (!isBST(root->left))
return false;

// Allows only distinct valued nodes
if (prev != NULL && root->data <= prev->data)
return false;

prev = root;

return isBST(root->right);
}

return true;
}

- kpl2tilwani91 July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

copied from geeksforgeeks

- Amit July 07, 2013 | 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