Marcy Blog

Failed to be a geek

Problem: Serialize and Deserialize Binary Tree

Question Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connecti...

Problem: Convert Sorted List to Binary Search Tree

Question Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree ...

Problem: Convert Sorted Array to Binary Search Tree

Question Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the...

Problem: Minimum Distance Between BST Nodes

Question Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Example : Input: root = [4,2,6,1,3,null...

Problem: Binary Search Tree Iterator

Question Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST. For...

Problem: Binary Tree Iterative Postorder Traversal

Question Given a binary tree, return the post order traversal of its nodes’ values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [3,2,1]. Note: Recursive s...

Problem: Binary Tree Iterative Preorder Traversal

Question Given a binary tree, return the preorder traversal of its nodes’ values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,2,3]. Note: Recursive sol...

Problem: Binary Tree Iterative Inorder Traversal

Question Given a binary tree, return the inorder traversal of its nodes’ values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2]. Note: Recursive solu...

Problem: Boundary of Binary Tree

Question Given a binary tree, return the values of its boundary in an anti-clockwise direction starting from the root. Boundary includes left boundary, leaves, and right boundary in order without ...

Problem: Convert BST to Greater Tree

Question Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in...