Citrix System Inc Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

Write functions:-
-> Node * Successor(Node * n)
-> Node * Predecessor(Node * n)

Suppose you have to insert a node having node pointer k.
Now k1 = Successor(k)
k2 = Predecessor(k)

and then do the following changes:-

k2->rand = k;
k->rand = k1;

These changes were made because before insertion of k, k2->rand was pointing to k1.

- Neeraj September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

node* FindLeftMost(node *n)
{
while(n->left != NULL)
n = n->left;
return n;
}

node * inOrderSuccessor(node *n, node *pred)
{
// step 1 of the above algorithm
if( n->right != NULL )
return FindLeftMost(n->right);

// step 2 of the above algorithm
return pred;
}

void Recurse(tree *root, tree *pred)
{
if(root == NULL) return;
node *temp = inOrderSuccessor(root, pred);
if(root->rand != temp)
root->rand = NULL;
Recurse(root->left, root);
Recurse(root->right, pred);
}

int main(void)
{
Recurse(root, NULL);
}

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

I think this code will be sufficient for all the three cases. It does not matter if it is BST or binary.

void foo(Node root)
{
	Node prev = null;
	if(root == null)
	{
		return;
	}
	
	foo(root.left);
	
	if(prev != null && prev.random == root)
	{
		// okay !!!
	}
	else
	{
		prev.random = null
	}
	prev = root;

	foo(root.right);
}

- dul007 March 09, 2014 | 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