Blogs Hub

by AskGif | Oct 06, 2020 | Category :coding

Sum of Left Leaves - Tree - Easy - LeetCode

Sum of Left Leaves - Tree - Easy - LeetCode

Find the sum of all left leaves in a given binary tree. Example: &nbsp; &nbsp; 3<br />&nbsp; &nbsp;/ \<br />&nbsp; 9 &nbsp;20<br />&nbsp; &nbsp; / &nbsp;\<br />&nbsp; &nbsp;15 &nbsp; 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.

read more...

by AskGif | Oct 06, 2020 | Category :coding

Binary Tree Paths - Tree - Easy - LeetCode

Binary Tree Paths - Tree - Easy - LeetCode

Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example: Input: &nbsp; &nbsp;1<br />&nbsp;/ &nbsp; \<br />2 &nbsp; &nbsp; 3<br />&nbsp;\<br />&nbsp; 5 Output: ["1-&gt;2-&gt;5", "1-&gt;3"] Explanation: All root-

read more...

by AskGif | Oct 06, 2020 | Category :coding

Path Sum - Tree - Easy - LeetCode

Path Sum - Tree - Easy - LeetCode

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. Note: A leaf is a node with no children. Example: Given the below binary tree and sum = 22, &nbsp; &nbsp; &nbsp; 5<br />

read more...

by AskGif | Oct 06, 2020 | Category :coding

Minimum Depth of Binary Tree - Tree - Easy - LeetCode

Minimum Depth of Binary Tree - Tree - Easy - LeetCode

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7], &nbsp; &n

read more...

by AskGif | Oct 06, 2020 | Category :coding

Balanced Binary Tree - Tree - Easy - LeetCode

Balanced Binary Tree - Tree - Easy - LeetCode

Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the left and right subtrees of every node differ in height by no more than 1. &nbsp; Example 1: Given the following tre

read more...

by AskGif | Oct 06, 2020 | Category :coding

Convert Sorted Array to Binary Search Tree - Tree - Easy - LeetCode

Convert Sorted Array to Binary Search Tree - Tree - Easy - LeetCode

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 depth of the two subtrees of every node never differ by more than 1. Example: Given the s

read more...

by AskGif | Oct 06, 2020 | Category :coding

Binary Tree Level Order Traversal II - Tree - Easy - LeetCode

Binary Tree Level Order Traversal II - Tree - Easy - LeetCode

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example:<br />Given binary tree [3,9,20,null,null,15,7],<br />&nbsp; &nbsp; 3<br />&nbsp; &nbsp;/ \<br />&nbsp; 9 &nbsp;20<br />&nbsp; &nbsp

read more...

by AskGif | Oct 06, 2020 | Category :coding

Maximum Depth of Binary Tree - Tree - Easy - LeetCode

Maximum Depth of Binary Tree - Tree - Easy - LeetCode

Given a binary 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. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7], &nbsp; &n

read more...

by AskGif | Oct 06, 2020 | Category :coding

Same Tree - Tree - Easy - LeetCode

Same Tree - Tree - Easy - LeetCode

Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes have the same value. Example 1: Input: &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; 1<br />&nbsp; &nbsp; &nb

read more...

by AskGif | Oct 06, 2020 | Category :coding

Number of Steps to Reduce a Number to Zero - Bit Manipulation - Easy - LeetCode

Number of Steps to Reduce a Number to Zero - Bit Manipulation - Easy - LeetCode

Given a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it. &nbsp; Example 1: Input: num = 14<br />Output: 6<br />Explanation:&nbsp;<br />Step 1) 14 is

read more...

by AskGif | Oct 06, 2020 | Category :coding

Prime Number of Set Bits in Binary Representation - Bit Manipulation - Easy - LeetCode

Prime Number of Set Bits in Binary Representation - Bit Manipulation - Easy - LeetCode

Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation. (Recall that the number of set bits an integer has is the number of 1s present when written in binary. For example, 21 written in binary i

read more...

by AskGif | Oct 06, 2020 | Category :coding

Binary Number with Alternating Bits - Bit Manipulation - Easy - LeetCode

Binary Number with Alternating Bits - Bit Manipulation - Easy - LeetCode

Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. &nbsp; Example 1: Input: n = 5<br />Output: true<br />Explanation: The binary representation of 5 is: 101<br />Example 2: Input: n = 7<br />

read more...