Microsoft - Phone screen | SDE | April 2020
Anonymous User
1353

Source - Referal

First 10 minutes - projects on my resume and past experience

Question 1:
Design structure of N-ary tree nodes

Question 2:
Serialize N-ary tree in following format
(root( (child 1 ( (Grandchild 1-1), (Grandchild 1-2) )), (child2 ( (Grandchild 2-1) )), (child3) ))

class Node:
	def __init__(self,value):
		self.value = value
		self.children = []



def searilize_tree(node):
	if node is None:
		return

	result = "(" + str(node.value)

	if len(node.children) > 0:
		result = "(" + str(node.value) + "("
		for child in node.children:
			result =  result + searilize_tree(child)
		result = result + ")"

	result = result + ")"

	return result




follow up : remove string concetination to reduce space complexity, use list append instead of string concetination and use "".join(result) for string at the end

Behavioral questions (2) - last 10 mins

Comments (2)