Samsung Interview Question for Senior Software Development Engineers


Country: United States
Interview Type: In-Person




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

C++ Version:

int isBST(struct node* node) { 
  return(checkIsBST(node, INT_MIN, INT_MAX)); 
}

int checkIsBST(struct node* node, int min, int max) { 
  if (node==NULL) 
	return true;

  if (node->data<min || node->data>max) 
	return false;

  return 
     ( checkIsBST(node->left, min, node->data) && 
       checkIsBST(node->right, node->data+1, max) ); 
}

- R@M3$H.N September 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public boolean checkBST(Node node)
{
if(node == null)
return true;

if(node.left != null && node.right != null)
{
if(node.left.value < node.value && node.right.value > node.value)
return true && checkBST(node.left) && checkBST(node.right);
}
else if(node.left != null && node.right == null)
{
if(node.left.value < node.value )
return true && checkBST(node.left);
}
else if(node.left == null && node.right != null)
{
if(node.right.value < node.value )
return true && checkBST(node.right);
}
else
{
return true;
}
return true;
}

- JAVA September 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public boolean checkBST(Node node)
{
if(node == null)
return true;

if(node.left != null && node.right != null)
{
if(node.left.value < node.value && node.right.value > node.value)
return true && checkBST(node.left) && checkBST(node.right);
}
else if(node.left != null && node.right == null)
{
if(node.left.value < node.value )
return true && checkBST(node.left);
}
else if(node.left == null && node.right != null)
{
if(node.right.value < node.value )
return true && checkBST(node.right);
}
else
{
return true;
}
return true;
}

- JAVA September 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

intialise the with (root,-inf,inf)

_Bool chk(struct node * r , int min,int max){
	if(r==NULL){
		return true;
	}else{
		if((r->val>min && r->val<max)){
			return (r->l,min,r->val)&&(r->r,r->val,max);
		}else{
			return false;
		}
	}
}

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

INORDER TRAVERSAL TO FIND BST

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

bool check_bst(node *root){
    if (root->data < root->left->data || root->data > root->right->data){
        return false
    }
    else if (root == NULL){
        return true
    }
    return(check_bst(root.left) & check_bst(root.right));
    
}

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

public boolean checkBST(Node node)
{
if(node == null)
return true;

if(node.left != null && node.right != null)
{
if(node.left.value < node.value && node.right.value > node.value)
return true && checkBST(node.left) && checkBST(node.right);
}
else if(node.left != null && node.right == null)
{
if(node.left.value < node.value )
return true && checkBST(node.left);
}
else if(node.left == null && node.right != null)
{
if(node.right.value > node.value )
return true && checkBST(node.right);
}
else
{
return true;
}
return true;
}

- purva7 June 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

int testBst(struct tree * root)
{
if (NULL == root)
return 0;
else
{
if (!( (!root->left || root->left->key < root->key) && (!root->right || root->right->key > root->key ) ))
return 0;
testBst(root->left);
testBst(root->right);
}
return 1;
}

- tauqir0007 September 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How about this case?

4
/
3
\
8

- R@M3$H.N September 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

An empty tree is a Valid BST. Your first case returns 0 ?

- R@M3$H.N September 24, 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