Google Virtual Onsite | India | July 2021 |[Offer - L4]
Anonymous User
2833

I appeared for Google, India interview in July 2021 for SWE position.

Phone Interview:

Please refer to the phone interview experience here:
https://leetcode.com/discuss/interview-experience/1327631/google-phone-interview-india-swe/1006970

Virtual Onsite:

Round1:

typedef struct TreeNode
{
	int pIndex;
} TreeNode;

Given a vector of TreeNode with structure mentioned below, implement deleteNodesByIndex method that meets following requirements

  1. The node specified by index is deleted.
  2. The children of deleted node become children of immediate parent.
  3. The size of vector reduces by 1. i.e. calling tree.size() should return previous tree size minus 1;

e.g.

Input:
[-1, 0, 0, 1, 1, 2, 2]

Output:
[-1, 0, 0, 0, 1, 1]

Explanation:

// Explanation Step 1:

index ->	  0  1  2  3  4  5  6
			[-1, 0, 0, 1, 1, 2, 2]
				 ^
				 |

				// This node will get deleted, and all the indexes after 1 will get reduced by 1

// Explanation Step 2:
index ->	  0  .  1  2  3  4  5   =>   // indices have been updated
			[-1, ., 0, 1, 1, 2, 2]  =>   // Since, indices have changed the stored parent indices also needs to be updated
				 ^
				 |

// Explanation Step 3: 

index ->	  0  .  1  2  3  4  5   =>   // Updated indices
			[-1, ., 0, 0, 0, 1, 1]  =>   // Replaced 2 with it's new index i.e. 1
				       ^  ^
				       |  |

						// For these parent would be marked as parent of deleted node. i.e. 0
						
//  Explanation Step 4:
// So finally, the array looks like 
[-1, 0, 0, 0, 1, 1]
	 

After deleting node at index 1, all the nodes after index one would get shifted towards the left, so their indexes will change. Also, the parent on nodes at index 3 and 4 in the original array would be changed to parent of deleted node i.e. 0.

The below diagrams are used for representation only
Original tree:

     0
	/ \
  1     2
 / \   / \
3   4  5  6

After deleting node at index 1:

      0
	/ | \
  2   3   1
		 / \
        4   5

Question 1

void deleteNodesByIndex(vector<TreeNode> tree, int index)
{
	// 1. The node specified by index is deleted.
	// 2. The children of deleted node become children of immediate parent.
	// 3. The size of vector reduces by 1. i.e. calling tree.size() should return previous tree  size minus 1;
}

Follow up:
Implement deleteNodesByIndex2 with following requirements

void deleteNodesByIndex2(vector<TreeNode> tree, int index)
{
	// 1. The subtree formed at the specified index is fully deleted.
	// 2. The size of vector reduced appropriately
}

e.g.

Original tree:

     0
	/ \
  1     2
 / \   / \
3   4  5  6

After deleting node at index 1:

      0
		\
	      1
		 / \
        2   3

 

Round 2

Question 1:

Given two lists A and B containing integers, return two lists (A - B) and (B - A)

(A - B) -> Elements of A not present in B
(B - A) -> Elements of B not present in A

A and B might contain duplicates

A = {1, 2, 2, 3, 4, 5}
B = {1, 3, 4, 7}
A - B = {2, 5}
B - A= {7}

Question 2:

Given a list of numbers, [3,4,5]. Return all possible numbers that can be formed using +-*/()

 

Round 3:

Given two BST, find list of common elements between them. The expected run time complexity should be bounded by O(n) and expected space complexity should be less than O(n).

e.g.

Tree A:
	3
   / \
  2   4

Tree B:
	2
   / \
  1   3

Result = [2, 3]

 

Round 4:

Question 1:
https://leetcode.com/problems/the-maze/

Follow up:
https://leetcode.com/problems/the-maze-ii/

 

Hope this is helpful. Please suggest, if any improvments are required in the post, I'll update it.

EDIT 1: Finally, after a long wait, received an L4 offer. All thanks to the LeetCode community :)

Comments (13)