## Sum of Left Leaves in Binary tree – LeetCode Solution [Easy]

Given the root of a binary tree, return the sum of all left leaves. Number of nodes in the tree lie in the range – [1, 1000]

## Lowest Common Ancestor of a Binary Search Tree – LeetCode Solution [Easy]

The lowest common ancestor is defined between two nodes p and q as the lowest node in Tre that has both p and q as descendants.

## Invert Binary Tree Solution in C++ – LeetCode [Easy]

Given the root of a binary tree, invert the tree, and return its root.

## Root to leaf path – LeetCode Solution [Easy]

Root to leaf path problem statement is:Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children. Example 1: Input: root = [3,9,20,null,null,15,7] Output: [“3->9″,”3->20->15″,”3->20->7”] Root to leaf path – Leetcode Solution Approach The idea is to use the DFS Traversal of the binary tree to […]

## Lowest Common Ancestor in a Binary Tree in C++

Problem Statement Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. Definition of LCA (according to Wikipedia) The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants. For the given Binary tree, if info[key1] = 15 and […]

## Determine if two trees are same in C++ – LeetCode Solution [Easy]

Given the roots of two binary trees p and q, 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 each identical node has the same value. Problem statement: https://leetcode.com/problems/same-tree/ Pseudocode 1. Traverse the given binary trees rooted at […]

## Find the Minimum Depth of Binary Tree in C++ – LeetCode Solution [Easy]

Problem StatementGiven 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 1: Input: root = [3,9,20,null,null,15,7]Output: 2 Find the Minimum Depth of […]

## Convert Sorted Array to Binary Search Tree in C++ – LeetCode Solution [Easy]

Problem Statement Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one. Example 1: Input: nums = [-10,-3,0,5,9] Output: [0,-3,9,-10,null,5] Approach This problem […]

## Print Binary tree in vertical order

Problem Statement Given a Binary tree, print it in vertical order from left to right. Vertical order for the above Binary tree is: Vertical order(root): 2 3 1 5 4 7 8 We could solve this problem by performing a breadth-first or level order traversal on the given tree and using […]

## Binary Search Tree in C/C++

In the last post we learnt about Binary Search Trees and basic operations like insert and search on them. In this post we’ll learn about some complex operations on them. Implementing Binary Search Tree operations in C/C++ Finding Minimum Element Tree-Minimum (root)1. while (left[root] != NULL)2. root = left[root]3. return root […]