Blogs Hub

by AskGif | Oct 08, 2020 | Category :coding

Two Sum IV - Input is a BST - Tree - Easy - LeetCode

Two Sum IV - Input is a BST - Tree - Easy - LeetCode

Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target. &nbsp; Example 1: <br />Input: root = [5,3,6,2,4,null,7], k = 9<br />Output: true<br />Example 2: <br />In

read more...

by AskGif | Oct 08, 2020 | Category :coding

Average of Levels in Binary Tree - Tree - Easy - LeetCode

Average of Levels in Binary Tree - Tree - Easy - LeetCode

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.<br />Example 1:<br />Input:<br />&nbsp; &nbsp; 3<br />&nbsp; &nbsp;/ \<br />&nbsp; 9 &nbsp;20<br />&nbsp; &nbsp; / &nbsp;\<br />&nbsp; &nbsp;15 &nbsp; 7<br />Output: [3, 14.5, 11]<br />Expl

read more...

by AskGif | Oct 08, 2020 | Category :coding

Merge Two Binary Trees - Tree - Easy - LeetCode

Merge Two Binary Trees - Tree - Easy - LeetCode

Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of

read more...

by AskGif | Oct 07, 2020 | Category :coding

Construct String from Binary Tree - Tree - Easy - LeetCode

Construct String from Binary Tree - Tree - Easy - LeetCode

You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be represented by empty parenthesis pair "()". And you need to omit all the empty parenthesis pairs that don't affect the one-to-one mapping relat

read more...

by AskGif | Oct 07, 2020 | Category :coding

N-ary Tree Postorder Traversal - Tree - Easy - LeetCode

N-ary Tree Postorder Traversal - Tree - Easy - LeetCode

Given an n-ary tree, return the postorder traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples). &nbsp; Follow up: Recursive solution is trivial,

read more...

by AskGif | Oct 07, 2020 | Category :coding

N-ary Tree Preorder Traversal - Tree - Easy - LeetCode

N-ary Tree Preorder Traversal - Tree - Easy - LeetCode

Given an n-ary tree, return the preorder traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples). &nbsp; Follow up: Recursive solution is trivial,

read more...

by AskGif | Oct 07, 2020 | Category :coding

Subtree of Another Tree - Tree - Easy - LeetCode

Subtree of Another Tree - Tree - Easy - LeetCode

Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node's descendants. The tree s could also be considered as a subtree of itself. Example 1:<br

read more...

by AskGif | Oct 07, 2020 | Category :coding

Binary Tree Tilt - Tree - Easy - LeetCode

Binary Tree Tilt - Tree - Easy - LeetCode

Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree node values. Null node has tilt 0. The tilt of the whole tree is defined as the sum

read more...

by AskGif | Oct 07, 2020 | Category :coding

Maximum Depth of N-ary Tree - Tree - Easy - LeetCode

Maximum Depth of N-ary Tree - Tree - Easy - LeetCode

Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null

read more...

by AskGif | Oct 07, 2020 | Category :coding

Diameter of Binary Tree - Tree - Easy - LeetCode

Diameter of Binary Tree - Tree - Easy - LeetCode

Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root. Example:<br />Given a binary tree<br />&nbsp; &nbsp; &nbsp; &nbs

read more...

by AskGif | Oct 07, 2020 | Category :coding

Minimum Absolute Difference in BST - Tree - Easy - LeetCode

Minimum Absolute Difference in BST - Tree - Easy - LeetCode

Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes. Example: Input: &nbsp; &nbsp;1<br />&nbsp; &nbsp; \<br />&nbsp; &nbsp; &nbsp;3<br />&nbsp; &nbsp; /<br />&nbsp; &nbsp;2 Output:<br />1 Expl

read more...

by AskGif | Oct 07, 2020 | Category :coding

Find Mode in Binary Search Tree - Tree - Easy - LeetCode

Find Mode in Binary Search Tree - Tree - Easy - LeetCode

Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than or equal to the node's key.<br />The right subtree o

read more...