DSA: BST
For Interview
Welcome to "Mastering Binary Search Trees (BST)," a comprehensive course designed to equip you with the skills and knowledge needed to understand, implement, and master Binary Search Trees. Binary Search Trees are a fundamental data structure widely used in computer science for efficient searching, insertion, and deletion operations.
- Day 1
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"Problem: Given the root of a binary tree, return its maximum depth."}]},{"_type":"paragraph","spans":[{"text":"A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node."}]},{"_type":"heading","level":3,"text":"Constraints"},{"_type":"paragraph","spans":[{"text":"The number of nodes in the tree is in the range [0, 10⁴]."}]},{"_type":"paragraph","spans":[{"text":"-100 ≤ Node.val ≤ 100"}]},{"_type":"heading","level":3,"text":"Example 1"},{"_type":"paragraph","spans":[{"text":"Input: root = [3,9,20,null,null,15,7]"}]},{"_type":"paragraph","spans":[{"text":"Output: 3"}]},{"_type":"heading","level":3,"text":"Example 2"},{"_type":"paragraph","spans":[{"text":"Input: root = [1,null,2]"}]},{"_type":"paragraph","spans":[{"text":"Output: 2"}]}]
- Day 2
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"\nGiven an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.\n\n\n\n\n\nConstraints:\n\n\n1 <= nums.length <= 10^4\n\n-10^4 <= nums[i] <= 10^4\n\nnums is sorted in a strictly increasing order.\n\n\n\n\nExample 1:\n\n\nInput: nums = [-10,-3,0,5,9]\n\nOutput: [0,-3,9,-10,null,5]\n\nExplanation: [0,-10,5,null,-3,null,9] is also accepted:\n\n\n\n\nExample 2:\n\n\nInput: nums = [1,3]\n\nOutput: [3,1]\n\nExplanation: [1,null,3] and [3,1] are both height-balanced BSTs.\n\n\n\n\n\n\n"}]}]
- Day 3
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"Please follow along the video in the integrated IDE"}]}]
- Day 4
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure."}]}]
- Day 5
Concept:
Resources:
Assignments:
[{"_type":"image","url":"https://skillcaptain-public.s3.ap-south-1.amazonaws.com/Screenshot+2024-03-20+at+10.05.07%E2%80%AFPM.png\n","alt":""}]
- Day 6
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"\nGiven the root of a binary tree, determine if it is a valid binary search tree (BST).\n\n\n\nA valid BST is defined as follows:\n\n\n\nThe left subtree of a node contains only nodes with keys less than the node's key.\n\nThe right subtree of a node contains only nodes with keys greater than the node's key.\n\nBoth the left and right subtrees must also be binary search trees.\n\n\n\nConstraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-2^31 <= Node.val <= 2^31 - 1\n\nExample\n\n"}]},{"_type":"image","url":"https://skillcaptain-public.s3.ap-south-1.amazonaws.com/Screenshot+2024-05-03+at+6.19.08%E2%80%AFPM.png","alt":""}]
- Day 7
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"\n\nGiven the root of a binary search tree (BST) and an integer target, split the tree into two subtrees where one subtree has nodes that are all smaller or equal to the target value, while the other subtree has all nodes that are greater than the target value. It Is not necessarily the case that the tree contains a node with the value target.\n\n\nAdditionally, most of the structure of the original tree should remain. Formally, for any child c with parent p in the original tree, if they are both in the same subtree after the split, then node c should still have the parent p.\n\n\nReturn an array of the two roots of the two subtrees.\n\n\n\nConstraints:\n\nThe number of nodes in the tree is in the range [1, 50].\n\n0 <= Node.val, target <= 1000\n\n\nExample:\n\n\n"}]},{"_type":"image","url":"https://skillcaptain-public.s3.ap-south-1.amazonaws.com/Screenshot+2024-05-08+at+5.09.29%E2%80%AFPM.png","alt":""}]
- Day 8
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"\n\nGiven the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it.\n\n\n\nIf the tree has more than one mode, return them in any order.\n\n\n\nAssume a BST is defined as follows:\n\n\n\nThe left subtree of a node contains only nodes with keys less than or equal to the node's key.\n\nThe right subtree of a node contains only nodes with keys greater than or equal to the node's key.\n\nBoth the left and right subtrees must also be binary search trees.\n\n\n\n\nConstraints:\n\n\nThe number of nodes in the tree is in the range [1, 10^4].\n\n-10^5 <= Node.val <= 10^5\n\n\n\nExample 1:\n\n\nInput: root = [1,null,2,2]\n\nOutput: [2]\n\n\n\nExample 2:\n\n\nInput: root = [0]\n\nOutput: [0]\n\n \n\n"}]}]
- Day 9
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"\n\nYou are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.\n\n\nNotice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.\n\n\n\n\nConstraints:\n\n\n\nThe number of nodes in the tree will be in the range [0, 10^4].\n\n-10^8 <= Node.val <= 10^8\n\nAll the values Node.val are unique.\n\n-10^8 <= val <= 10^8\n\nIt's guaranteed that val does not exist in the original BST.\n\n\n\n\nExample 1:\n\nInput: root = [4,2,7,1,3], val = 5\n\nOutput: [4,2,7,1,3,5]\n\nExplanation: Another accepted tree is:\n\n\n\nExample 2:\n\nInput: root = [40,20,60,10,30,50,70], val = 25\n\nOutput: [40,20,60,10,30,50,70,null,null,25]\n\n\n\nExample 3:\n\nInput: root = [4,2,7,1,3,null,null,null,null,null,null], val = 5\n\nOutput: [4,2,7,1,3,5]\n\n \n\n"}]}]
- Day 10
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"\n\nYou are given the root of a binary search tree (BST) and an integer val.\n\n\nFind the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null.\n\n\n\nConstraints:\n\n\n\nThe number of nodes in the tree is in the range [1, 5000].\n\n1 <= Node.val <= 10^7\n\nroot is a binary search tree.\n\n1 <= val <= 10^7\n\n\n\n\nExample 1:\n\nInput: root = [4,2,7,1,3], val = 2\n\nOutput: [2,1,3]\n\n\n\n\nExample 2:\n\nInput: root = [4,2,7,1,3], val = 5\n\nOutput: []\n\n\n"}]}]
- Day 11
Concept:
Resources:
Assignments:
[{"_type":"paragraph","spans":[{"text":"\nJust read and understand what Binary Trees and BSTs are.\n\nNo need to write any code — just get familiar with the basics.\n"}]}]