## 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

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);
}``````

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);
}``````

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;
}

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

copied from geeksforgeeks

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.

### 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.