Google Coding Interview Question: Serialize & Deserialize A Binary Tree (Java Solution)

Published: 07 June 2020
on channel: Daily Coding Problem
398
4

Google Coding Interview Question: Serialize & Deserialize A Binary Tree (Java Solution)

Not employed by dailycodingproblem.com, just a fan.

You can (and should) sign up to receive an email with a coding problem everyday here: https://www.dailycodingproblem.com

You can subscribe to my channel here:    / @dailycodingproblem8346  

Daily Coding Problem: Problem #3 [Medium]
Good morning! Here's your coding interview problem for today.

This problem was asked by Google.

Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree.

For example, given the following Node class

class Node:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
The following test should pass:

node = Node('root', Node('left', Node('left.left')), Node('right'))
assert deserialize(serialize(node)).left.left.val == 'left.left'

Solution involves recursion and pre-order traversal of a tree


On this page of the site you can watch the video online Google Coding Interview Question: Serialize & Deserialize A Binary Tree (Java Solution) with a duration of hours minute second in good quality, which was uploaded by the user Daily Coding Problem 07 June 2020, share the link with friends and acquaintances, this video has already been watched 398 times on youtube and it was liked by 4 viewers. Enjoy your viewing!