Blogs Hub

by AskGif | Oct 09, 2020 | Category :coding

Flood Fill - Tree - Easy - LeetCode

Flood Fill - Tree - Easy - LeetCode

An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535). Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perfor

read more...

by AskGif | Oct 09, 2020 | Category :coding

Sum of Root To Leaf Binary Numbers - Tree - Easy - LeetCode

Sum of Root To Leaf Binary Numbers - Tree - Easy - LeetCode

You are given the root of a binary tree where each node has a value 0 or 1. &nbsp;Each root-to-leaf path represents a binary number starting with the most significant bit. &nbsp;For example, if the path is 0 -&gt; 1 -&gt; 1 -&gt; 0 -&gt; 1, then this could represent 01101 in binary, which is 13.<

read more...

by AskGif | Oct 09, 2020 | Category :coding

Cousins in Binary Tree - Tree - Easy - LeetCode

Cousins in Binary Tree - Tree - Easy - LeetCode

In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1. Two nodes of a binary tree are cousins if they have the same depth, but have different parents. We are given the root of a binary tree with unique values, and the values x and y of two

read more...

by AskGif | Oct 09, 2020 | Category :coding

Univalued Binary Tree - Tree - Easy - LeetCode

Univalued Binary Tree - Tree - Easy - LeetCode

A binary tree is univalued if every node in the tree has the same value. Return true if and only if the given tree is univalued. &nbsp; Example 1: <br />Input: [1,1,1,1,1,null,1]<br />Output: true<br />Example 2: <br />Input: [2,2,2,5,2]<br />Output: false<br />

read more...

by AskGif | Oct 09, 2020 | Category :coding

Range Sum of BST - Tree - Easy - LeetCode

Range Sum of BST - Tree - Easy - LeetCode

Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive). The binary search tree is guaranteed to have unique values. &nbsp; Example 1: Input: root = [10,5,15,3,7,null,18], L = 7, R = 15<br />Output: 32<b

read more...

by AskGif | Oct 09, 2020 | Category :coding

Increasing Order Search Tree - Tree - Easy - LeetCode

Increasing Order Search Tree - Tree - Easy - LeetCode

Given a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only 1 right child. Example 1:<br />Input: [5,3,6,2,4,null,8,1,null,null,null,7,9] &nbsp; &nbsp; &nbsp; &nbsp;5<br />&nb

read more...

by AskGif | Oct 09, 2020 | Category :coding

Leaf-Similar Trees - Tree - Easy - LeetCode

Leaf-Similar Trees - Tree - Easy - LeetCode

Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence. For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8). Two binary trees are considered leaf-similar if their leaf value sequence is t

read more...

by AskGif | Oct 09, 2020 | Category :coding

Minimum Distance Between BST Nodes - Tree - Easy - LeetCode

Minimum Distance Between BST Nodes - Tree - Easy - LeetCode

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,null]<br />Output: 1<br />Explanation:<br />Note that root is a TreeNode object, not an array.</

read more...

by AskGif | Oct 09, 2020 | Category :coding

Search in a Binary Search Tree - Tree - Easy - LeetCode

Search in a Binary Search Tree - Tree - Easy - LeetCode

Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Return the subtree rooted with that node. If such node doesn't exist, you should return NULL. For example,&nbsp; Given the tree:<br />&nb

read more...

by AskGif | Oct 08, 2020 | Category :coding

Longest Univalue Path - Tree - Easy - LeetCode

Longest Univalue Path - Tree - Easy - LeetCode

Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root. The length of path between two nodes is represented by the number of edges between them. &nbsp; Example 1: Input:</p

read more...

by AskGif | Oct 08, 2020 | Category :coding

Second Minimum Node In a Binary Tree - Tree - Easy - LeetCode

Second Minimum Node In a Binary Tree - Tree - Easy - LeetCode

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes. More formally, the property root.val = min(root

read more...

by AskGif | Oct 08, 2020 | Category :coding

Trim a Binary Search Tree - Tree - Easy - LeetCode

Trim a Binary Search Tree - Tree - Easy - LeetCode

Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should rem

read more...