## Gaile

BAN USER- 0of 2 votes

Answers8 coins are given where all the coins have equal weight, except one. The odd one may be less weight than the other or it may be heavier than the rest 7 coins. In worst case, how many iterations are needed to find the odd one out?

- Gaile in United States| Report Duplicate | Flag | PURGE

VMWare Inc Software Engineer / Developer - 1of 1 vote

AnswersAn array which is a Post order traversal of a Binary Tree. Write a function to check if the Binary Tree formed from the array is a Binary Search Tree.

- Gaile in United States

Eg:

2

1 3

The array given as input would be 1 3 2.

Write a function to say if the tree formed is a Binary Search Tree.

Example 2: 4 is root. 0 is left child of 1 , 1 is left child of 2 and 2 is left child of 4. 5 is right child of 4 and 6 is right child of 5.

4

2 5

1 6

0

0 1 2 6 5 4 is the input array.| Report Duplicate | Flag | PURGE

VMWare Inc Software Engineer / Developer - 4of 4 votes

AnswersConsider the array 3 5 7 6 3.

- Gaile in United States

Return the pair of indices that forms the slice where the difference between the maximum and minimum in the slice <= 2.

Output:

(0,0) (1,1) (2,2) (3,3) (4,4) (5,5)

(0,1) (1,2) (1,3) (2,3)

Example slices: 3 5, 5 7, 1 3, 2 3.

The following link

https://codility.com/media/train/solution-count-bounded-slices.pdf

has O ( n ) solution. But couldn't understand the O (n ) solution. Could some one explain with an example?| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer - 0of 0 votes

AnswersExplain some of the text encoding types and advantages/disadvantages of each.

- Gaile in United States| Report Duplicate | Flag | PURGE

Apple SDE1 - 0of 0 votes

AnswersIf your browser crashes, how would you debug it only using the command line?

- Gaile in United States| Report Duplicate | Flag | PURGE

Apple SDE1 - 0of 0 votes

AnswersThere are 3 ants at 3 corners of an equilateral triangle they randomly start moving towards another corner what is the probability that they do not collide? Follow up: Suppose if all ants go in same direction(say ant 1 travels from point A to B, ant 2 from B to C and ant 3 from C to A. Either all ant travels in clockwise or anti clockwise) when will they collide

- Gaile in United States| Report Duplicate | Flag | PURGE

Apple SDE1 - 0of 0 votes

Answersdesign an iterator over a LinkedList of LinkedList's

- Gaile in United States| Report Duplicate | Flag | PURGE

Apple SDE1 - 0of 0 votes

AnswersHow will you sort 1 billion integers stored in an array?

- Gaile in United States| Report Duplicate | Flag | PURGE

Apple SDE1 - 1of 1 vote

AnswersHaving two distinct very large ordered array of values, find the mean value(not median) of the two arrays.

- Gaile in United States| Report Duplicate | Flag | PURGE

Apple SDE1 - 2of 2 votes

AnswersYou have a 100 coins laying flat on a table, each with a head side and a tail side. 10 of them are heads up, 90 are tails up. You can't feel, see or in any other way find out which side is up. Split the coins into two piles such that there are the same number of heads in each pile.

- Gaile in United States| Report Duplicate | Flag | PURGE

Apple SDE1 - 0of 0 votes

AnswersModel an elevator.

- Gaile in United States| Report Duplicate | Flag | PURGE

Apple SDE1 - 1of 1 vote

AnswersImplement an iterator for a binary search tree that will iterate the nodes by value in ascending order

- Gaile in United States| Report Duplicate | Flag | PURGE

Apple SDE1 - 0of 0 votes

AnswersHow to sort 2 queues without additional containers?

- Gaile in United States| Report Duplicate | Flag | PURGE

Microsoft SDE1 - -5of 5 votes

AnswersWhat is the in order successor of 6 in the given BST? (Ah! This is not an assignment. I am a working professional).

- Gaile in United States

4

2 6

1 3 5

4.5 5.5

2 is left child of 4 and 6 is right child of 4.

1 is left child of 2 and 3 is right child of 3.

5 is left child of 6.

4.5 is left child of 5 and 5.5 is right child of 5.| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Algorithm

I have come up with a solution for finding the in order successor when the links to parents are not provided. Could you check if this is right? I already checked. I would feel confident if someone cross checks it.

public Node inOrder(Node n, Node root){

if(root == null){

return null;

}

Node successor;

Node max;

while(root != null && root != n.data){

Node parent = root; // 4 // 6

if(root.left != null && n.data <= root){

if(root >= max){

max = root; // 6

}

root = root.left; //5

successor = parent; //6

}else if(root.right != null && n.data >= root){

if(root >= max){

max = root; //

}

root = root.right; //

successor = parent; //

}

}

if(root.right == null && root == parent.left){

return max;

}

if(root.right != null){

return leftMostChild(root);

}

}

public Node leftMostChild(Node n){

Node current;

if(n.right != null){

current = n.right;

}

while(current.left != null){

current = current.left;

}

return current;

}

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Will it work for m --> aam ?

- Gaile March 11, 2015