From 9881610b787c7d7d91d46cae67dca3d1ee0c68e0 Mon Sep 17 00:00:00 2001 From: Anshika Yadav <14anshika7yadav@gmail.com> Date: Sun, 9 Jun 2024 22:46:39 +0530 Subject: [PATCH 1/8] Solution of Leetcode Problem: 98 #872 --- .../0098-validate-binary-search-tree.md | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md diff --git a/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md b/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md new file mode 100644 index 000000000..52d43d05e --- /dev/null +++ b/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md @@ -0,0 +1,95 @@ +--- +id: validate binary search tree +title: Validate Binary Search Tree +sidebar_label: 0098 Validate Binary Search Tree +tags: + - tree + - tree traversal + - LeetCode + - C++ +description: "This is a solution to the Validate Binary Search Tree problem on LeetCode." +--- + +## Problem Description + +Given the root of a binary tree, determine if it is a valid binary search tree (BST). + +A valid BST is defined as follows: + +* The left subtree of a node contains only nodes with keys less than the node's key. +* The right subtree of a node contains only nodes with keys greater than the node's key. +* Both the left and right subtrees must also be binary search trees. + +### Examples + +**Example 1:** + +``` + +Input: root = [2,1,3] +Output: true +``` + +**Example 2:** + +``` +Input: root = [5,1,4,null,null,3,6] +Output: false +``` + +### Constraints + +- The number of nodes in the tree is in the range $[1, 10^4]$. +- -2^(31) <= Node.val <= 2^(31) - 1. + +### Approach + +To solve this problem(valid BST) we will do the inorder traversal of the tree as we know in a binary search tree the array of elements which we get after inorder traversal they will be in sorted order so after the inorder traversal we will just have check if the inorder traversal of the given binary search is in sorted order or not. + +#### Code in C++ + +```cpp +/** + * Definition for a binary tree node. + * struct TreeNode { + * int val; + * TreeNode *left; + * TreeNode *right; + * TreeNode() : val(0), left(nullptr), right(nullptr) {} + * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), + * right(right) {} + * }; + */ +class Solution { +public: + // Function for inorder traversal + void inorder(TreeNode* root , vector&a){ + if(root==NULL){ + return; + } + inorder(root->left,a); + a.push_back(root->val); + inorder(root->right,a); + } + bool isValidBST(TreeNode* root) { + vectora,b; + inorder(root,a); + b=a; + for(int i=1;i Date: Sun, 9 Jun 2024 23:41:13 +0530 Subject: [PATCH 2/8] update --- ...7-letter-combinations-of-a-phone-number.md | 377 ++++++++++++------ 1 file changed, 250 insertions(+), 127 deletions(-) diff --git a/dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md b/dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md index a112c79fb..de07f5ca6 100644 --- a/dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md +++ b/dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md @@ -1,89 +1,104 @@ --- -id: letter-combinations-of-a-phone-number +id: Letter Combinations of a Phone Number title: Letter Combinations of a Phone Number (LeetCode) -sidebar_label: 0017-Letter Combinations of a Phone Number +sidebar_label: 0017-Letter-Combinations-of-a-Phone-Number tags: - - String - - Backtracking -description: "Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent." + - Back Tracking + - Mapping + - String +description: The problem requires generating all letter combinations corresponding to given digits (2-9). The solution utilizes backtracking to explore all combinations efficiently, employing a recursive approach in Java. --- ## Problem Description | Problem Statement | Solution Link | LeetCode Profile | | :----------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------- | -| [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/) | [Letter Combinations of a Phone Number Solution on LeetCode](https://leetcode.com/problems/letter-combinations-of-a-phone-number/solutions/) | [gabaniyash846](https://leetcode.com/u/gabaniyash846/) | +| [Letter Combinations of a Phone Number](https://leetcode.com/problems/Letter Combinations of a Phone Number/) | [Letter Combinations of a Phone Number Solution on LeetCode](https://leetcode.com/problems/Letter Combinations of a Phone Number/solutions/5055810/video-two-pointer-solution/) | [gabaniyash846](https://leetcode.com/u/gabaniyash846/) | ### Problem Description +## Problem Statement: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. -A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. - ### Examples #### Example 1 + - **Input:** `digits = "23"` - **Output:** `["ad","ae","af","bd","be","bf","cd","ce","cf"]` #### Example 2 + - **Input:** `digits = ""` - **Output:** `[]` + #### Example 3 -- **Input:** `digits = "2"` + +- **Input:** `2` - **Output:** `["a","b","c"]` -### Constraints -- `0 <= digits.length <= 4` -- `digits[i]` is a digit in the range `['2', '9']`. +### Constraints: +- `0 ≤ digits.length ≤ 4` +- `0 ≤ digits.length ≤ 4digits[𝑖]` +- `digits[i] is a digit in the range ['2', '9'].` +- `A mapping of digits to letters (similar to telephone buttons) is given below. Note that 1 does not map to any letters.` -### Topics -- String -- Backtracking +### Approach -### Intuition -- Use backtracking to generate all possible combinations. +1. **Mapping Digits to Letters:** + - Define a mapping of digits to their corresponding letters, similar to telephone buttons. -### Complexity -- **Time Complexity:** $O(3^N \cdot 4^M)$ where $N$ is the number of digits in the input that maps to 3 letters (2, 3, 4, 5, 6, 8) and $M$ is the number of digits in the input that maps to 4 letters (7, 9). -- **Space Complexity:** $O(3^N \cdot 4^M)$ for storing the results. +2. **Backtracking Function:** + - Define a recursive backtracking function to generate all possible combinations. + - The function takes four parameters: + - `index`: The current index in the digits string. + - `path`: The current combination of letters. + - If the index is equal to the length of the digits string, it means we have reached the end of a combination, so we add it to the result list. + - Otherwise, for each letter corresponding to the current digit, we append it to the current combination and recursively call the function with the next index. + - After the recursive call, we remove the last character from the combination (backtracking). -### Solution Code and Explanation +3. **Base Case:** + - If the length of the current combination is equal to the length of the input digits string, we add the combination to the result list. -#### C++ +4. **Main Function:** + - Initialize an empty list to store the combinations. + - Call the backtracking function with the initial index set to 0 and an empty string as the initial combination. + - Return the list of combinations. -```cpp -#include -#include -#include +This approach ensures that all possible combinations are generated using backtracking, and the result is returned in the desired format. -class Solution { -public: - std::vector letterCombinations(std::string digits) { - if (digits.empty()) return {}; - std::unordered_map phoneMap = { - {'2', "abc"}, {'3', "def"}, {'4', "ghi"}, - {'5', "jkl"}, {'6', "mno"}, {'7', "pqrs"}, - {'8', "tuv"}, {'9', "wxyz"} - }; - std::vector result; - backtrack(digits, phoneMap, 0, "", result); - return result; - } +### Solution Code -private: - void backtrack(const std::string& digits, const std::unordered_map& phoneMap, int index, std::string current, std::vector& result) { - if (index == digits.size()) { - result.push_back(current); - return; - } - const std::string& letters = phoneMap.at(digits[index]); - for (const char& letter : letters) { - backtrack(digits, phoneMap, index + 1, current + letter, result); +#### Python + +```python +class Solution: + def letterCombinations(self, digits: str) -> List[str]: + if not digits: + return [] + + digit_to_letters = { + '2': 'abc', + '3': 'def', + '4': 'ghi', + '5': 'jkl', + '6': 'mno', + '7': 'pqrs', + '8': 'tuv', + '9': 'wxyz' } - } -}; + + def backtrack(index, path): + if index == len(digits): + combinations.append(path) + return + for letter in digit_to_letters[digits[index]]: + backtrack(index + 1, path + letter) + + combinations = [] + backtrack(0, '') + return combinations ``` #### Java @@ -94,100 +109,208 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -class Solution { +public class Solution { + private Map digitToLetters = new HashMap<>(); + + public Solution() { + digitToLetters.put('2', "abc"); + digitToLetters.put('3', "def"); + digitToLetters.put('4', "ghi"); + digitToLetters.put('5', "jkl"); + digitToLetters.put('6', "mno"); + digitToLetters.put('7', "pqrs"); + digitToLetters.put('8', "tuv"); + digitToLetters.put('9', "wxyz"); + } + public List letterCombinations(String digits) { - List result = new ArrayList<>(); - if (digits.isEmpty()) return result; - Map phoneMap = new HashMap<>() {{ - put('2', "abc"); - put('3', "def"); - put('4', "ghi"); - put('5', "jkl"); - put('6', "mno"); - put('7', "pqrs"); - put('8', "tuv"); - put('9', "wxyz"); - }}; - backtrack(digits, phoneMap, 0, new StringBuilder(), result); - return result; + List combinations = new ArrayList<>(); + if (digits == null || digits.isEmpty()) { + return combinations; + } + backtrack(combinations, digits, 0, new StringBuilder()); + return combinations; } - private void backtrack(String digits, Map phoneMap, int index, StringBuilder current, List result) { + private void backtrack(List combinations, String digits, int index, StringBuilder path) { if (index == digits.length()) { - result.add(current.toString()); + combinations.add(path.toString()); return; } - String letters = phoneMap.get(digits.charAt(index)); + String letters = digitToLetters.get(digits.charAt(index)); for (char letter : letters.toCharArray()) { - current.append(letter); - backtrack(digits, phoneMap, index + 1, current, result); - current.deleteCharAt(current.length() - 1); + path.append(letter); + backtrack(combinations, digits, index + 1, path); + path.deleteCharAt(path.length() - 1); } } + + public static void main(String[] args) { + Solution solution = new Solution(); + List result = solution.letterCombinations("23"); + System.out.println(result); // Output: [ad, ae, af, bd, be, bf, cd, ce, cf] + } } ``` -#### Python +#### CPP: +```cpp +#include +#include +#include -```python -from typing import List +using namespace std; -class Solution: - def letterCombinations(self, digits: str) -> List[str]: - if not digits: - return [] - - phone_map = { - "2": "abc", "3": "def", "4": "ghi", "5": "jkl", - "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz" +class Solution { +private: + unordered_map digitToLetters; + vector combinations; + +public: + Solution() { + digitToLetters = { + {'2', "abc"}, + {'3', "def"}, + {'4', "ghi"}, + {'5', "jkl"}, + {'6', "mno"}, + {'7', "pqrs"}, + {'8', "tuv"}, + {'9', "wxyz"} + }; + } + + vector letterCombinations(string digits) { + if (digits.empty()) return {}; + backtrack(digits, 0, ""); + return combinations; + } + + void backtrack(const string& digits, int index, string path) { + if (index == digits.length()) { + combinations.push_back(path); + return; + } + for (char letter : digitToLetters[digits[index]]) { + backtrack(digits, index + 1, path + letter); + } + } +}; + +int main() { + Solution solution; + vector result = solution.letterCombinations("23"); + for (const string& comb : result) { + cout << comb << " "; + } + // Output: ad ae af bd be bf cd ce cf + return 0; +} +``` + +#### JavaScript +```js +/** + * @param {string} digits + * @return {string[]} + */ +var letterCombinations = function(digits) { + if (digits.length === 0) return []; + + const digitToLetters = { + '2': 'abc', + '3': 'def', + '4': 'ghi', + '5': 'jkl', + '6': 'mno', + '7': 'pqrs', + '8': 'tuv', + '9': 'wxyz' + }; + + const combinations = []; + + const backtrack = (index, path) => { + if (index === digits.length) { + combinations.push(path); + return; + } + const letters = digitToLetters[digits.charAt(index)]; + for (let letter of letters) { + backtrack(index + 1, path + letter); + } + }; + + backtrack(0, ''); + return combinations; +}; + +// Example usage: +console.log(letterCombinations("23")); // Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] +``` + +#### TypeScript +```ts +class Solution { + private digitToLetters: { [key: string]: string } = { + '2': 'abc', + '3': 'def', + '4': 'ghi', + '5': 'jkl', + '6': 'mno', + '7': 'pqrs', + '8': 'tuv', + '9': 'wxyz' + }; + + letterCombinations(digits: string): string[] { + const combinations: string[] = []; + + const backtrack = (index: number, path: string): void => { + if (index === digits.length) { + combinations.push(path); + return; + } + const letters = this.digitToLetters[digits.charAt(index)]; + for (let letter of letters) { + backtrack(index + 1, path + letter); + } + }; + + if (digits.length !== 0) { + backtrack(0, ''); } - def backtrack(index: int, path: str): - if index == len(digits): - combinations.append(path) - return - possible_letters = phone_map[digits[index]] - for letter in possible_letters: - backtrack(index + 1, path + letter) - - combinations = [] - backtrack(0, "") - return combinations + return combinations; + } +} + +// Example usage: +const solution = new Solution(); +console.log(solution.letterCombinations("23")); // Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] ``` -### Explanation +### Step-by-Step Algorithm -1. **Initialize Phone Map:** - Create a mapping from digit to corresponding letters. - ```python - phone_map = { - "2": "abc", "3": "def", "4": "ghi", "5": "jkl", - "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz" - } - ``` +Here's a step-by-step algorithm for generating all possible letter combinations of a given string of digits using backtracking: -2. **Backtracking Function:** - Define a recursive function `backtrack` to generate combinations. - - **Base case:** If the current index is equal to the length of digits, add the current path to combinations. - - **Recursive case:** For each letter corresponding to the current digit, append the letter to the path and call `backtrack` with the next index. - ```python - def backtrack(index: int, path: str): - if index == len(digits): - combinations.append(path) - return - possible_letters = phone_map[digits[index]] - for letter in possible_letters: - backtrack(index + 1, path + letter) - ``` - -3. **Initiate Backtracking:** - Initialize the result list `combinations` and start the backtracking process. - ```python - combinations = [] - backtrack(0, "") - return combinations - ``` - -### Conclusion - -The above solution efficiently generates all possible letter combinations for a given string of digits. It employs a backtracking approach to explore all potential combinations, leveraging a recursive function to build the combinations step-by-step. The time complexity of $O(3^N \cdot 4^M)$ and space complexity of $O(3^N \cdot 4^M)$ ensure that the algorithm can handle input sizes up to the upper limit specified in the constraints efficiently. +1. **Define a mapping of digits to letters:** + - Create a map where each digit from 2 to 9 is mapped to its corresponding letters on a telephone keypad. + +2. **Define a backtracking function:** + - The function will take the following parameters: + - `index`: The current index in the digits string. + - `path`: The current combination of letters. + - If the index is equal to the length of the digits string, it means we have formed a complete combination, so add it to the result list. + - Otherwise, for each letter corresponding to the current digit at the given index, append it to the current combination and recursively call the function with the next index. + - After the recursive call, remove the last character from the combination (backtracking). + +3. **Base Case:** + - If the length of the current combination is equal to the length of the input digits string, add the combination to the result list. + +4. **Main Function:** + - Initialize an empty list to store the combinations. + - Call the backtracking function with the initial index set to 0 and an empty string as the initial combination. + - Return the list of combinations. + +This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking. \ No newline at end of file From 4536583e1e904eed7da2e53e7b1dc73c59c8416b Mon Sep 17 00:00:00 2001 From: Anshika Yadav <14anshika7yadav@gmail.com> Date: Mon, 10 Jun 2024 08:21:57 +0530 Subject: [PATCH 3/8] Change made --- .../lc-solutions/0000-0099/0098-validate-binary-search-tree.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md b/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md index 52d43d05e..e5f8ad87d 100644 --- a/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md +++ b/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md @@ -40,7 +40,7 @@ Output: false ### Constraints - The number of nodes in the tree is in the range $[1, 10^4]$. -- -2^(31) <= Node.val <= 2^(31) - 1. +- `-2^(31) <= Node.val <= 2^(31) - 1.` ### Approach From 561a17fbabcc9efb2fad6993afc4315cb1cda993 Mon Sep 17 00:00:00 2001 From: Anshika Yadav <14anshika7yadav@gmail.com> Date: Mon, 10 Jun 2024 08:48:32 +0530 Subject: [PATCH 4/8] Leetcode Problem:230 #883 --- .../0230-Kth-smallest-element-in-BST.md | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 dsa-solutions/lc-solutions/0200-0299/0230-Kth-smallest-element-in-BST.md diff --git a/dsa-solutions/lc-solutions/0200-0299/0230-Kth-smallest-element-in-BST.md b/dsa-solutions/lc-solutions/0200-0299/0230-Kth-smallest-element-in-BST.md new file mode 100644 index 000000000..383dc4e8b --- /dev/null +++ b/dsa-solutions/lc-solutions/0200-0299/0230-Kth-smallest-element-in-BST.md @@ -0,0 +1,78 @@ +--- +id: kth smallest element in binary search tree +title: Kth Smallest Element in Binary Search Tree +sidebar_label: 0230 Kth Smallest Element in Binary Search Tree +tags: + - tree + - tree traversal + - LeetCode + - C++ +description: "This is a solution to theKth Smallest Element in Binary Search Tree problem on LeetCode." +--- + +## 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. + +### Examples + +**Example 1:** + +``` + +Input: root = [3,1,4,null,2], k = 1 +Output: 1 +``` + +**Example 2:** + +``` +Input: root = [5,3,6,2,4,null,null,1], k = 3 +Output: 3 +``` + +### Constraints + +- The number of nodes in the tree is n. +- `1 <= k <= n <= 10^4` +- `0 <= Node.val <= 10^4` + +### Approach + +To solve this problem(Kth smallest element in BST) we will do the inorder traversal of the tree as we know in a binary search tree the array of elements which we get after inorder traversal they will be in sorted order so the kth smallest element in the given BST will be the kth index(1-indexed) element in inorder traversal of the BST. + +#### Code in C++ + +```cpp +/** + * Definition for a binary tree node. + * struct TreeNode { + * int val; + * TreeNode *left; + * TreeNode *right; + * TreeNode() : val(0), left(nullptr), right(nullptr) {} + * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} + * }; + */ +class Solution { +public: + // Function for inorder traversal + void inorder(TreeNode* root,vector&a){ + if(root==NULL){ + return; + } + inorder(root->left,a); + a.push_back(root->val); + inorder(root->right,a); + } + // Function to get the kth smallest element + int kthSmallest(TreeNode* root, int k) { + vectora; + inorder(root,a); + return a[k-1]; // as 0-indexed + } +}; +``` + + From 89dd670772de4827c93ff5ff40025386a4e081d7 Mon Sep 17 00:00:00 2001 From: Anshika Yadav <14anshika7yadav@gmail.com> Date: Mon, 10 Jun 2024 09:10:51 +0530 Subject: [PATCH 5/8] Added Leetcode Problem:226 #908 --- .../0226-invert-binary-search-tree.md | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 dsa-solutions/lc-solutions/0200-0299/0226-invert-binary-search-tree.md diff --git a/dsa-solutions/lc-solutions/0200-0299/0226-invert-binary-search-tree.md b/dsa-solutions/lc-solutions/0200-0299/0226-invert-binary-search-tree.md new file mode 100644 index 000000000..d3558b2d9 --- /dev/null +++ b/dsa-solutions/lc-solutions/0200-0299/0226-invert-binary-search-tree.md @@ -0,0 +1,83 @@ +--- +id: invert binary search tree +title: Invert Binary Search Tree +sidebar_label: 0226 Invert Binary Search Tree +tags: + - tree + - recursion + - LeetCode + - C++ +description: "This is a solution to the Invert Binary Search Tree problem on LeetCode." +--- + +## Problem Description + +Given the root of a binary tree, invert the tree, and return its root. + +### Examples + +**Example 1:** + +``` + +Input: root = [4,2,7,1,3,6,9] +Output: [4,7,2,9,6,3,1] +``` + +**Example 2:** + +``` +Input: root = [2,1,3] +Output: [2,3,1] +``` + +``` +Input: root = [] +Output: [] +``` + +### Constraints + +- The number of nodes in the tree is in the range $[0, 100]$. +- `-100 <= Node.val <= 100` + +### Approach + +To solve this problem(invert BST) we will use recursion(call function repeatedly) and temporary tree node(t) for swapping. + +#### Code in C++ + +```cpp +/** + * Definition for a binary tree node. + * struct TreeNode { + * int val; + * TreeNode *left; + * TreeNode *right; + * TreeNode() : val(0), left(nullptr), right(nullptr) {} + * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} + * }; + */ +class Solution { +public: + void invert(TreeNode* root){ + if(root==NULL){ + return; + } + TreeNode* t; + t=root->right; + root->right=root->left; + root->left=t; + invert(root->left); + invert(root->right); + } + TreeNode* invertTree(TreeNode* root) { + invert(root); + return root; + + } +}; +``` + + From 27a21dd8693b6cdf7ae3e050bbe18c79c7673945 Mon Sep 17 00:00:00 2001 From: Anshika Yadav <14anshika7yadav@gmail.com> Date: Mon, 10 Jun 2024 11:22:11 +0530 Subject: [PATCH 6/8] updated --- .../lc-solutions/0200-0299/0226-invert-binary-search-tree.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dsa-solutions/lc-solutions/0200-0299/0226-invert-binary-search-tree.md b/dsa-solutions/lc-solutions/0200-0299/0226-invert-binary-search-tree.md index d3558b2d9..82d145fa0 100644 --- a/dsa-solutions/lc-solutions/0200-0299/0226-invert-binary-search-tree.md +++ b/dsa-solutions/lc-solutions/0200-0299/0226-invert-binary-search-tree.md @@ -1,5 +1,5 @@ --- -id: invert binary search tree +id: invert-binary-search-tree title: Invert Binary Search Tree sidebar_label: 0226 Invert Binary Search Tree tags: @@ -39,7 +39,7 @@ Output: [] ### Constraints - The number of nodes in the tree is in the range $[0, 100]$. -- `-100 <= Node.val <= 100` +- $-100 \leq \text{Node.val} \leq 100$ ### Approach From c1f583fbfbf9d6d6564c65f951a2c36ec8a5673b Mon Sep 17 00:00:00 2001 From: Ajay Dhangar <99037494+Ajay-Dhangar@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:20:47 +0530 Subject: [PATCH 7/8] Update 0098-validate-binary-search-tree.md --- .../0000-0099/0098-validate-binary-search-tree.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md b/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md index e5f8ad87d..c2828e3f4 100644 --- a/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md +++ b/dsa-solutions/lc-solutions/0000-0099/0098-validate-binary-search-tree.md @@ -1,5 +1,5 @@ --- -id: validate binary search tree +id: validate-binary-search-tree title: Validate Binary Search Tree sidebar_label: 0098 Validate Binary Search Tree tags: @@ -40,7 +40,7 @@ Output: false ### Constraints - The number of nodes in the tree is in the range $[1, 10^4]$. -- `-2^(31) <= Node.val <= 2^(31) - 1.` +- $-2^(31) \leq \text{Node.val} \leq 2^(31) - 1$. ### Approach From 1aadb6fa4609e169e1b8e2ea380f46c4bc419ac6 Mon Sep 17 00:00:00 2001 From: Ajay Dhangar <99037494+Ajay-Dhangar@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:22:46 +0530 Subject: [PATCH 8/8] Update 0230-Kth-smallest-element-in-BST.md --- .../0200-0299/0230-Kth-smallest-element-in-BST.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dsa-solutions/lc-solutions/0200-0299/0230-Kth-smallest-element-in-BST.md b/dsa-solutions/lc-solutions/0200-0299/0230-Kth-smallest-element-in-BST.md index 383dc4e8b..d963cc57e 100644 --- a/dsa-solutions/lc-solutions/0200-0299/0230-Kth-smallest-element-in-BST.md +++ b/dsa-solutions/lc-solutions/0200-0299/0230-Kth-smallest-element-in-BST.md @@ -1,5 +1,5 @@ --- -id: kth smallest element in binary search tree +id: kth-smallest-element-in-binary-search-tree title: Kth Smallest Element in Binary Search Tree sidebar_label: 0230 Kth Smallest Element in Binary Search Tree tags: @@ -34,8 +34,8 @@ Output: 3 ### Constraints - The number of nodes in the tree is n. -- `1 <= k <= n <= 10^4` -- `0 <= Node.val <= 10^4` +- $1 \leq k \leq n \leq 10^4$ +- $0 \leq \text{Node.val} \leq 10^4$ ### Approach