Tableau Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

public Node successor(Node root, int value) {
        Node curr = root;
        Node result = null;
        while (curr != null) {
            if (curr.value <= value) {
                curr = curr.right;
            } else {
                result = curr;
                curr = curr.left;
            }
        }
        return result;
    }

- ajit@ajitk.in September 26, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

this is nothing but finding the inorder successor of a value in BST

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

Pre-order, in-order, post-order traversal?

- Iuri Sitinschi September 25, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is nothing but finding the inorder successor of a value in BST

- Priya September 25, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

c code
-------------------

#include<stdio.h>
#include<alloc.h>
struct BST
{
int data;
struct BST*Lc,*Rc;
}*head=NULL;
void InsertData(int);
void Dispay(struct BST*);
void DispayNextElement(int);
main()
{
int value;
char insert='y';
while(insert=='y'||insert=='Y')
{
printf("\n Enter one (int) data:-");
scanf("%d",&value);
InsertData(value);
fflush(stdin);
printf("\n Eneter another element(y/n):=");
scanf("%c",&insert);
}
Dispay(head);
insert='y';
while(insert=='y'||insert=='Y')
{
printf("\n Enter find next data:-");
scanf("%d",&value);
DispayNextElement(value);
fflush(stdin);
printf("\n Find another element(y/n):=");
scanf("%c",&insert);
}
}
void DispayNextElement(int value)
{
	int i=0;
	if(head==NULL)
	printf("no Element in this tree");
	else
	{
     struct BST*temp=head;
	while(temp!=NULL)
	{
		if(temp->data>value)
		{
			temp=temp->Lc;
		}
		else if(temp->data<value)
		{
			temp=temp->Rc;
		}
		else if(temp->data==value) 
		{
			break;
		}
		else
		{
			printf("\n Element Not Persent");
			return;
		}
	}
	if(temp!=NULL&&temp->data==value)
	{
		if(temp->Lc!=NULL)
		printf("\nnext data:- %d",temp->Lc->data);
		else if(temp->Rc!=NULL)
		printf("\n next daat:- %d",temp->Rc->data);
		else
		printf("\n No next element");
	}
	else
	{
	   printf("\n element not present ");	
	}
    }
}
void Dispay(struct BST* temp)
{
if(temp==NULL)
return;
else
{
Dispay(temp->Lc);
printf("%5d",temp->data);
Dispay(temp->Rc);
}
}

void InsertData(int value)
{
struct BST*temp=head,*element=(struct BST*)malloc(sizeof(struct BST));
element->Lc=NULL;
element->Rc=NULL;
element->data=value;
if(head==NULL)
head=element;
else
{
while(temp!=NULL)
{
if(temp->data>=value)
{
if(temp->Lc!=NULL)
temp=temp->Lc;
else
{
temp->Lc=element;
break;
}
}
else
{
if(temp->Rc!=NULL)
temp=temp->Rc;
else
{
temp->Rc=element;
break;
}
}
}
}
}

--------------------------- 
OutPut...

 Enter one (int) data:-20

 Eneter another element(y/n):=y

 Enter one (int) data:-17

 Eneter another element(y/n):=y

 Enter one (int) data:-23

 Eneter another element(y/n):=y

 Enter one (int) data:-6

 Eneter another element(y/n):=y

 Enter one (int) data:-18

 Eneter another element(y/n):=y

 Enter one (int) data:-25

 Eneter another element(y/n):=y

 Enter one (int) data:-5

 Eneter another element(y/n):=y

 Enter one (int) data:-8

 Eneter another element(y/n):=y

 Enter one (int) data:-24

 Eneter another element(y/n):=y

 Enter one (int) data:-29

 Eneter another element(y/n):=y

 Enter one (int) data:-10

 Eneter another element(y/n):=y

 Enter one (int) data:-9

 Eneter another element(y/n):=n
    5    6    8    9   10   17   18   20   23   24   25   29
 Enter find next data:-78

 element not present
 Find another element(y/n):=y

 Enter find next data:-17

next data:- 6
 Find another element(y/n):=y

 Enter find next data:-24

 No next element
 Find another element(y/n):=y

 Enter find next data:-25

next data:- 24
 Find another element(y/n):=n

--------------------------------

- Anonymous January 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

c code
-------------------

#include<stdio.h>
#include<alloc.h>
struct BST
{
int data;
struct BST*Lc,*Rc;
}*head=NULL;
void InsertData(int);
void Dispay(struct BST*);
void DispayNextElement(int);
main()
{
int value;
char insert='y';
while(insert=='y'||insert=='Y')
{
printf("\n Enter one (int) data:-");
scanf("%d",&value);
InsertData(value);
fflush(stdin);
printf("\n Eneter another element(y/n):=");
scanf("%c",&insert);
}
Dispay(head);
insert='y';
while(insert=='y'||insert=='Y')
{
printf("\n Enter find next data:-");
scanf("%d",&value);
DispayNextElement(value);
fflush(stdin);
printf("\n Find another element(y/n):=");
scanf("%c",&insert);
}
}
void DispayNextElement(int value)
{
	int i=0;
	if(head==NULL)
	printf("no Element in this tree");
	else
	{
     struct BST*temp=head;
	while(temp!=NULL)
	{
		if(temp->data>value)
		{
			temp=temp->Lc;
		}
		else if(temp->data<value)
		{
			temp=temp->Rc;
		}
		else if(temp->data==value) 
		{
			break;
		}
		else
		{
			printf("\n Element Not Persent");
			return;
		}
	}
	if(temp!=NULL&&temp->data==value)
	{
		if(temp->Lc!=NULL)
		printf("\nnext data:- %d",temp->Lc->data);
		else if(temp->Rc!=NULL)
		printf("\n next daat:- %d",temp->Rc->data);
		else
		printf("\n No next element");
	}
	else
	{
	   printf("\n element not present ");	
	}
    }
}
void Dispay(struct BST* temp)
{
if(temp==NULL)
return;
else
{
Dispay(temp->Lc);
printf("%5d",temp->data);
Dispay(temp->Rc);
}
}

void InsertData(int value)
{
struct BST*temp=head,*element=(struct BST*)malloc(sizeof(struct BST));
element->Lc=NULL;
element->Rc=NULL;
element->data=value;
if(head==NULL)
head=element;
else
{
while(temp!=NULL)
{
if(temp->data>=value)
{
if(temp->Lc!=NULL)
temp=temp->Lc;
else
{
temp->Lc=element;
break;
}
}
else
{
if(temp->Rc!=NULL)
temp=temp->Rc;
else
{
temp->Rc=element;
break;
}
}
}
}
}

--------------------------- 
OutPut...

 Enter one (int) data:-20

 Eneter another element(y/n):=y

 Enter one (int) data:-17

 Eneter another element(y/n):=y

 Enter one (int) data:-23

 Eneter another element(y/n):=y

 Enter one (int) data:-6

 Eneter another element(y/n):=y

 Enter one (int) data:-18

 Eneter another element(y/n):=y

 Enter one (int) data:-25

 Eneter another element(y/n):=y

 Enter one (int) data:-5

 Eneter another element(y/n):=y

 Enter one (int) data:-8

 Eneter another element(y/n):=y

 Enter one (int) data:-24

 Eneter another element(y/n):=y

 Enter one (int) data:-29

 Eneter another element(y/n):=y

 Enter one (int) data:-10

 Eneter another element(y/n):=y

 Enter one (int) data:-9

 Eneter another element(y/n):=n
    5    6    8    9   10   17   18   20   23   24   25   29
 Enter find next data:-78

 element not present
 Find another element(y/n):=y

 Enter find next data:-17

next data:- 6
 Find another element(y/n):=y

 Enter find next data:-24

 No next element
 Find another element(y/n):=y

 Enter find next data:-25

next data:- 24
 Find another element(y/n):=n

--------------------------------

- nandu deshmukh January 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private class Node
        {
            public Node RightNode;
            public Node LeftNode;
            public int Value;
        }

        private static int FindNextVal(Node node, int key)
        {
            var n = Search(node, key);

            if (n == null || (n.LeftNode == null && n.RightNode == null))
                return -1;

            return n.RightNode != null ? n.RightNode.Value : n.LeftNode.Value;

        }

        private static Node Search(Node node, int key)
        {
            if (node is null)
                return null;

            if (node.Value == key)
                return node;

            if (key < node.Value)
                return Search(node.LeftNode, key);
            else
                return Search(node.RightNode, key);
        }

        private static Node LoadTree()
        {
            var tree = new Node();

            return new Node
            {
                Value = 20,
                LeftNode = new Node
                {
                    Value = 15,
                    LeftNode = new Node
                    {
                        Value = 13
                    },
                    RightNode = new Node { Value = 16 }
                },
                RightNode = new Node
                {
                    Value = 25,
                    RightNode = new Node
                    {
                        Value = 45
                    },
                    LeftNode = new Node
                    {
                        Value = 22
                    }
                }
            };
        }

- Mike June 19, 2018 | 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