Home
Gaurav's GitHub Page
Cancel

Morris Traversal

PROBLEM DESCRIPTION Binary Tree traversal using Morris Algorithm. Iterative approach, no stack required - O(1) space complexity. geeksforgeeks SOLUTION Using Morris Traversal, we can traverse th...

Construct Binary Tree from Inorder and Postorder Traversal

PROBLEM DESCRIPTION Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and ...

Binary Tree Right Side View

PROBLEM DESCRIPTION Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Leetcode SOLUTION ...

Kth Smallest Element in a BST

PROBLEM DESCRIPTION Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree. Leetcode SOLUTION APPROACH 1 ...

Equal Tree Partition - Binary Tree

PROBLEM DESCRIPTION Given the root of a binary tree, return true if you can partition the tree into two trees with equal sums of values after removing exactly one edge on the original tree. leetco...

Recover Binary Search Tree

PROBLEM DESCRIPTION Two elements of a binary search tree (BST), represented by root A are swapped by mistake. Tell us the 2 values swapping which the tree will be restored. interviewbit SOLUTION ...

Least Common Ancestor - Binary Tree

PROBLEM DESCRIPTION Find the lowest common ancestor in an unordered binary tree A, given two values, B and C, in the tree. Leetcode SOLUTION Get root to node path: YouTube In the previous s...

Valid Binary Search Tree

PROBLEM DESCRIPTION Given the root of a binary tree, determine if it is a valid binary search tree (BST). leetcode SOLUTION public class Solution { public int isValidBST(TreeNode A) { ...

Delete a Node in Binary Search Tree

PROBLEM DESCRIPTION Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. leetcode SOLUTION...

Construct Binary Tree from Preorder and Inorder Traversal

PROBLEM DESCRIPTION Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and ret...