question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
validate-binary-search-tree | Simple JS DFS | simple-js-dfs-by-pranaykmr-xnln | \nvar isValidBST = function(root, min = -Infinity, max = Infinity) {\n if(root === null)\n return true;\n if(root.val <= min || root.val >= max)\n | pranaykmr | NORMAL | 2021-02-02T22:15:51.795195+00:00 | 2021-02-02T22:15:51.795241+00:00 | 3,490 | false | ```\nvar isValidBST = function(root, min = -Infinity, max = Infinity) {\n if(root === null)\n return true;\n if(root.val <= min || root.val >= max)\n return false;\n return isValidBST(root.right, root.val, max) && isValidBST(root.left, min, root.val)\n};\n``` | 24 | 0 | ['JavaScript'] | 2 |
validate-binary-search-tree | ✅ 🔥 0 ms Runtime Beats 100% User🔥|| Code Idea ✅ || Algorithm & Solving Step ✅ || | 0-ms-runtime-beats-100-user-code-idea-al-xhjk | \n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n BST property:\n\n1. The left subtree contains only nodes with keys less than the no | Letssoumen | NORMAL | 2024-12-02T00:34:01.100405+00:00 | 2024-12-02T00:34:01.100432+00:00 | 3,780 | false | \n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n **BST property**:\n\n1. The left subtree contains only nodes with keys **less than** the node\... | 23 | 1 | ['Tree', 'Depth-First Search', 'C++', 'Java', 'Python3'] | 0 |
validate-binary-search-tree | C++ Solution Using LONG_MAX and LONG_MIN | c-solution-using-long_max-and-long_min-b-2nca | \tclass Solution {\n\tpublic:\n\t\tbool isValidBSTHelper(TreeNode root, long min, long max) {\n\t\t\tif(root == NULL){\n\t\t\t\treturn true;\n\t\t\t} \n\t\t\t | pankajgupta20 | NORMAL | 2021-05-13T09:47:37.388499+00:00 | 2021-06-03T16:40:52.248230+00:00 | 2,693 | false | \tclass Solution {\n\tpublic:\n\t\tbool isValidBSTHelper(TreeNode* root, long min, long max) {\n\t\t\tif(root == NULL){\n\t\t\t\treturn true;\n\t\t\t} \n\t\t\tif(root->val > min && root->val < max) {\n\t\t\t\treturn isValidBSTHelper(root->left, min, root->val) && isValidBSTHelper(root->right, root->val, max);\n\t\t\t... | 23 | 0 | ['Recursion', 'C', 'C++'] | 6 |
validate-binary-search-tree | Recursive approach✅ | O( n)✅ | (Step by step explanation)✅ | recursive-approach-o-n-step-by-step-expl-bo12 | Intuition\nThe problem requires checking whether a binary tree is a valid binary search tree (BST). A BST is a binary tree where for each node, the values of al | monster0Freason | NORMAL | 2023-11-14T04:47:30.733304+00:00 | 2023-11-14T04:47:30.733326+00:00 | 3,500 | false | # Intuition\nThe problem requires checking whether a binary tree is a valid binary search tree (BST). A BST is a binary tree where for each node, the values of all nodes in its left subtree are less than the node\'s value, and the values of all nodes in its right subtree are greater than the node\'s value.\n\n# Approac... | 22 | 0 | ['Tree', 'Depth-First Search', 'Recursion', 'C++', 'Python3'] | 2 |
validate-binary-search-tree | Beats 100% | Only 3 LINES Code ->Diagram & Image Best Explaination🥇 | C++/Python/Java 🔥 | beats-100-only-3-lines-code-diagram-imag-gda5 | Diagram Data Flow\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\nBefore we start properties to verify BST are:\n- Top root node | 7mm | NORMAL | 2023-05-29T10:15:41.402002+00:00 | 2023-05-29T10:15:41.402033+00:00 | 6,483 | false | # Diagram Data Flow\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Approach\n**Before we start properties to verify BST are:**\n- Top root node should have range -... | 22 | 0 | ['Tree', 'Binary Search Tree', 'Recursion', 'Binary Tree', 'C++'] | 3 |
validate-binary-search-tree | 🔥 Python || Easily Understood ✅ || Faster than 96% || Recursion | python-easily-understood-faster-than-96-nm9z9 | Method: recursion\n\ndef isValidBST(self, root: Optional[TreeNode]) -> bool:\n\tdef check_validate(root, lower, upper):\n\t\tif not root:\n\t\t\treturn True\n\t | wingskh | NORMAL | 2022-08-11T05:05:13.193881+00:00 | 2022-08-12T09:41:16.592513+00:00 | 2,786 | false | Method: `recursion`\n```\ndef isValidBST(self, root: Optional[TreeNode]) -> bool:\n\tdef check_validate(root, lower, upper):\n\t\tif not root:\n\t\t\treturn True\n\t\tif lower >= root.val or upper <= root.val:\n\t\t\treturn False\n\t\telse:\n\t\t\treturn check_validate(root.left, lower, root.val) and check_validate(\n\... | 22 | 0 | ['Recursion', 'Python'] | 2 |
validate-binary-search-tree | C++ | DFS Recursion | Time: O (n), Space: O (n) | c-dfs-recursion-time-o-n-space-o-n-by-hi-zc1z | DFS Recusive Approach\nThe reason why we update min and max at every step is because:\n1. For every left node, the max value it can have it less than its parent | hiitsme | NORMAL | 2020-12-13T05:16:15.456740+00:00 | 2022-02-22T02:45:34.537603+00:00 | 3,802 | false | **DFS Recusive Approach**\nThe reason why we update min and max at every step is because:\n1. For every left node, the max value it can have it less than its parent\'s and the min value it can have is the left most node for that particular subtree.\n2. For every right node, the max value it can have it less than the ri... | 22 | 0 | ['Stack', 'Recursion', 'C', 'Iterator'] | 3 |
validate-binary-search-tree | Easy to understand 2 lines solution! O(n) with Examples and Explanation - JavaScript | easy-to-understand-2-lines-solution-on-w-4m7e | Short and sweet:\n\nts\nfunction isValidBST(root: TreeNode|null, min = -Infinity, max = Infinity): boolean {\n if(!root) return true;\n return !(root.val <= m | adriansky | NORMAL | 2020-08-10T13:23:11.952883+00:00 | 2020-08-10T13:23:33.839826+00:00 | 2,351 | false | Short and sweet:\n\n```ts\nfunction isValidBST(root: TreeNode|null, min = -Infinity, max = Infinity): boolean {\n if(!root) return true;\n return !(root.val <= min || root.val >= max) && isValidBST(root.left, min, root.val) && isValidBST(root.right, root.val, max);\n};\n```\n\nHow it works?\n- If the root is `null`, ... | 22 | 0 | ['TypeScript', 'JavaScript'] | 4 |
validate-binary-search-tree | Accepted Java solution | accepted-java-solution-by-vy7sun-hjy8 | import java.util.Stack;\n\npublic class Solution {\n\nStack stack = new Stack();\n\npublic void inOrder(TreeNode root){\n\n if(root != null){\n inOrde | vy7sun | NORMAL | 2015-03-12T06:07:41+00:00 | 2015-03-12T06:07:41+00:00 | 6,762 | false | import java.util.Stack;\n\npublic class Solution {\n\nStack<Integer> stack = new Stack<Integer>();\n\npublic void inOrder(TreeNode root){\n\n if(root != null){\n inOrder(root.left);\n stack.push(root.val);\n inOrder(root.right);\n }\n}\npublic boolean isValidBST(TreeNode root){\n\n if(root... | 22 | 2 | [] | 7 |
validate-binary-search-tree | 1ms Java solution, O(n) time and O(1) space, using Integer object and null pointer | 1ms-java-solution-on-time-and-o1-space-u-m34c | public class Solution {\n public boolean isValidBST(TreeNode root) {\n return isValidBSTHelper(root, null, null);\n }\n \n pr | yanggao | NORMAL | 2015-11-11T18:11:43+00:00 | 2015-11-11T18:11:43+00:00 | 5,306 | false | public class Solution {\n public boolean isValidBST(TreeNode root) {\n return isValidBSTHelper(root, null, null);\n }\n \n private boolean isValidBSTHelper(TreeNode root, Integer leftBound, Integer rightBound) {\n // recursively pass left and right bounds from higher le... | 21 | 3 | [] | 5 |
validate-binary-search-tree | Easy || 0 ms || 100% || Fully Explained || Java, C++, Python, JS, C, Python3 || DFS | easy-0-ms-100-fully-explained-java-c-pyt-2mcy | Java Solution:\n\n// Runtime: 0 ms, faster than 100.00% of Java online submissions for Validate Binary Search Tree.\nclass Solution {\n public boolean isVali | PratikSen07 | NORMAL | 2022-08-30T10:35:48.562898+00:00 | 2022-08-30T10:43:45.999392+00:00 | 4,926 | false | # **Java Solution:**\n```\n// Runtime: 0 ms, faster than 100.00% of Java online submissions for Validate Binary Search Tree.\nclass Solution {\n public boolean isValidBST(TreeNode root) {\n return isValidBST(root, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); \n } \n public boolean isValidBST(T... | 20 | 0 | ['Tree', 'Depth-First Search', 'C', 'Python', 'Java', 'Python3', 'JavaScript'] | 5 |
validate-binary-search-tree | ✅Java|| 0ms 100% Faster||Beginner Friendly | java-0ms-100-fasterbeginner-friendly-by-oa5xu | If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries | ganajayant | NORMAL | 2022-08-11T01:50:19.558914+00:00 | 2022-08-12T10:44:52.800799+00:00 | 1,456 | false | **If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries or some improvements please feel free to comment and share your views.**\n\n```\npublic boolean isValidBST(TreeNode root) {\n return isValid(root, Long... | 20 | 4 | ['Binary Search Tree', 'Recursion', 'Java'] | 1 |
validate-binary-search-tree | JAVA || Easy Solution || 100% faster Code | java-easy-solution-100-faster-code-by-sh-bbt6 | \tPLEASE UPVOTE IF YOU LIKE\n\nclass Solution {\n private boolean flag=true;\n TreeNode prev=null;\n public boolean isValidBST(TreeNode root) {\n | shivrastogi | NORMAL | 2022-08-11T02:59:05.277441+00:00 | 2022-08-11T02:59:05.277491+00:00 | 3,007 | false | \tPLEASE UPVOTE IF YOU LIKE\n```\nclass Solution {\n private boolean flag=true;\n TreeNode prev=null;\n public boolean isValidBST(TreeNode root) {\n inorder(root);\n return flag;\n }\n public void inorder(TreeNode root){\n if(root==null) return;\n \n inorder(root.left);... | 19 | 2 | ['Java'] | 4 |
validate-binary-search-tree | Python easy to understand iterative and recursive solutions | python-easy-to-understand-iterative-and-y8jkc | \nclass Solution(object):\n def isValidBST(self, root):\n return self.valid(root, -sys.maxsize, sys.maxsize)\n \n def valid(self, root, l, r):\n | oldcodingfarmer | NORMAL | 2015-08-14T15:51:08+00:00 | 2020-09-24T13:33:05.414583+00:00 | 7,203 | false | ```\nclass Solution(object):\n def isValidBST(self, root):\n return self.valid(root, -sys.maxsize, sys.maxsize)\n \n def valid(self, root, l, r):\n if not root:\n return True\n if not (l < root.val < r):\n return False\n return self.valid(root.left, l, root.val... | 19 | 1 | ['Recursion', 'Iterator', 'Python'] | 6 |
validate-binary-search-tree | Python || InOrder Traversal || Easy To Understand 🔥 | python-inorder-traversal-easy-to-underst-21fu | Code\n\nclass Solution:\n def isValidBST(self, root: Optional[TreeNode]) -> bool:\n arr = []\n def inorder(root):\n if root is None: | karanjadaun22 | NORMAL | 2023-02-21T08:38:19.945290+00:00 | 2023-02-21T08:38:19.945322+00:00 | 6,508 | false | # Code\n```\nclass Solution:\n def isValidBST(self, root: Optional[TreeNode]) -> bool:\n arr = []\n def inorder(root):\n if root is None: return None\n inorder(root.left)\n arr.append(root.val)\n inorder(root.right)\n inorder(root)\n return True... | 18 | 0 | ['Python3'] | 5 |
validate-binary-search-tree | ✔️ Simple Python Solution to Validate Binary Search Tree using Recursion 🔥 | simple-python-solution-to-validate-binar-mhdl | IF YOU FIND THIS POST HELPFUL PLEASE UPVOTE \uD83D\uDC4D\n\n\nclass Solution:\n def isValidBST(self, root: Optional[TreeNode]) -> bool:\n \n de | pniraj657 | NORMAL | 2022-10-15T04:51:05.006743+00:00 | 2022-11-02T03:29:28.353316+00:00 | 6,058 | false | **IF YOU FIND THIS POST HELPFUL PLEASE UPVOTE \uD83D\uDC4D**\n\n```\nclass Solution:\n def isValidBST(self, root: Optional[TreeNode]) -> bool:\n \n def valid(node, left, right):\n if not node:\n return True\n if not (node.val<right and node.val>left):\n ... | 17 | 1 | ['Binary Search Tree', 'Recursion', 'Python', 'Python3'] | 3 |
validate-binary-search-tree | Go: 4ms | go-4ms-by-ayenter-fv98 | \nfunc isValidBST(root *TreeNode) bool {\n return RecValidate(root, nil, nil)\n}\n\nfunc RecValidate(n, min, max *TreeNode) bool {\n if n == nil {\n | ayenter | NORMAL | 2020-02-15T19:06:46.914338+00:00 | 2020-02-15T19:06:46.914372+00:00 | 1,641 | false | ```\nfunc isValidBST(root *TreeNode) bool {\n return RecValidate(root, nil, nil)\n}\n\nfunc RecValidate(n, min, max *TreeNode) bool {\n if n == nil {\n return true\n }\n if min != nil && n.Val <= min.Val {\n return false\n }\n if max != nil && n.Val >= max.Val {\n return false\n ... | 16 | 0 | ['Go'] | 2 |
validate-binary-search-tree | Simple DFS solution | C# | simple-dfs-solution-c-by-baymax-7yxy | Intuition & Approach\n Describe your first thoughts on how to solve this problem. \nSince all the nodes in the left-sub-tree should be less than the current nod | Baymax_ | NORMAL | 2023-05-05T04:37:19.526216+00:00 | 2023-05-05T04:37:31.169719+00:00 | 1,604 | false | # Intuition & Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince all the nodes in the left-sub-tree should be less than the current node, and all the nodes in the right-sub-tree should be greater than the current node, we can iterate down to check if each node satisfies the condition, ... | 15 | 0 | ['Tree', 'Depth-First Search', 'Binary Search Tree', 'Binary Tree', 'C#'] | 2 |
validate-binary-search-tree | 4 line C++ simple solution, easy understanding | 4-line-c-simple-solution-easy-understand-dlif | bool isValidBST(TreeNode* root) {\n return dfs_valid(root, LONG_MIN, LONG_MAX);\n }\n bool dfs_valid(TreeNode *root, long low, long high) {\n | lchen77 | NORMAL | 2015-12-14T00:54:02+00:00 | 2015-12-14T00:54:02+00:00 | 4,167 | false | bool isValidBST(TreeNode* root) {\n return dfs_valid(root, LONG_MIN, LONG_MAX);\n }\n bool dfs_valid(TreeNode *root, long low, long high) {\n if (!root) return true;\n return low < root->val && root->val < high && dfs_valid(root->left, low, root->val)\n && dfs_valid(root->... | 15 | 1 | ['C++'] | 3 |
validate-binary-search-tree | Superb Lgic BST | superb-lgic-bst-by-ganjinaveen-phrz | \nclass Solution:\n def isValidBST(self, root: Optional[TreeNode]) -> bool:\n def BST(root,mx,mi):\n if not root:\n return T | GANJINAVEEN | NORMAL | 2023-07-15T23:57:25.425820+00:00 | 2023-07-15T23:57:25.425844+00:00 | 2,258 | false | ```\nclass Solution:\n def isValidBST(self, root: Optional[TreeNode]) -> bool:\n def BST(root,mx,mi):\n if not root:\n return True\n elif root.val>=mx or root.val<=mi:\n return False\n else:\n return BST(root.left,root.val,mi) and B... | 14 | 0 | ['Binary Search Tree', 'Python', 'Python3'] | 1 |
validate-binary-search-tree | Java recursive solution 0ms, without using Long.MAX_VALUE and Long.MIN_VALUE | java-recursive-solution-0ms-without-usin-tjqt | Approach\nFor this problem, we need to choose one biggest value > Integer.MAX_VALUE\nand one smallest value < Integer.MIN_VALUE as the maximum and minimum, resp | xian-wen | NORMAL | 2023-03-02T09:44:08.443696+00:00 | 2023-04-05T12:38:38.033051+00:00 | 3,186 | false | # Approach\nFor this problem, we need to choose one biggest value > `Integer.MAX_VALUE`\nand one smallest value < `Integer.MIN_VALUE` as the maximum and minimum, respectively. They could not be equal, otherwise cases like\n```\nroot = [2147483647]\nroot = [2147483647, 2147483647]\n```\nwill be failed.\n\n`Long.MAX_VALU... | 13 | 0 | ['Java'] | 3 |
validate-binary-search-tree | C++ / Python simple O(n) solution | c-python-simple-on-solution-by-tovam-jk2p | C++ :\n\n\nclass Solution {\npublic:\n void inorder(TreeNode* root)\n {\n if(!root)\n return;\n \n inorder(root -> left);\ | TovAm | NORMAL | 2021-10-07T12:28:59.063568+00:00 | 2021-10-07T12:28:59.063600+00:00 | 1,907 | false | **C++ :**\n\n```\nclass Solution {\npublic:\n void inorder(TreeNode* root)\n {\n if(!root)\n return;\n \n inorder(root -> left);\n bTree.push_back(root -> val);\n inorder(root -> right);\n }\n\n bool isValidBST(TreeNode* root) {\n // An empty tree\n ... | 13 | 0 | ['C', 'Python', 'Python3'] | 2 |
validate-binary-search-tree | Test cases missing | test-cases-missing-by-loick-9zt1 | There should be a test case where some nodes have values equal to Integer.MIN_VALUE and Integer.MAX_VALUE;\n\nThis solution is accepted and shouldn't be:\n\n | loick | NORMAL | 2013-12-05T09:36:57+00:00 | 2013-12-05T09:36:57+00:00 | 3,607 | false | There should be a test case where some nodes have values equal to Integer.MIN_VALUE and Integer.MAX_VALUE;\n\nThis solution is accepted and shouldn't be:\n\n public boolean isValidBST(TreeNode root) {\n if (root == null) return true;\n return isValidBST(root.left,Integer.MIN_VALUE, root.val) \n ... | 13 | 1 | [] | 6 |
validate-binary-search-tree | 1 ms Java Solution | 1-ms-java-solution-by-harish20-nudr | public class Solution {\n private TreeNode prev = null;\n \n public boolean isValidBST(TreeNode root) {\n if(root == null){\n | harish20 | NORMAL | 2016-04-26T06:49:13+00:00 | 2016-04-26T06:49:13+00:00 | 1,333 | false | public class Solution {\n private TreeNode prev = null;\n \n public boolean isValidBST(TreeNode root) {\n if(root == null){\n return true;\n }\n if(!isValidBST(root.left)) return false;\n if(prev != null && root.val <= prev.val) return ... | 13 | 1 | [] | 1 |
validate-binary-search-tree | Three solutions in C++ | three-solutions-in-c-by-zefengsong-6wiq | Solution 1. \n\nBF, O(n^2).\n\nclass Solution {\npublic:\n bool isValidBST(TreeNode* root) {\n if(!root) return true;\n if(!isValid(root->left, | zefengsong | NORMAL | 2017-08-19T11:22:29.554000+00:00 | 2017-08-19T11:22:29.554000+00:00 | 3,098 | false | **Solution 1.** \n\nBF, O(n^2).\n```\nclass Solution {\npublic:\n bool isValidBST(TreeNode* root) {\n if(!root) return true;\n if(!isValid(root->left, root->val, true) || !isValid(root->right, root->val, false)) return false;\n return isValidBST(root->left) && isValidBST(root->right);\n }\n ... | 13 | 0 | ['C++'] | 3 |
validate-binary-search-tree | 4 BEST C++ solutions || Recursive, iterative and inorder approach || Beats 100% !! | 4-best-c-solutions-recursive-iterative-a-0997 | Code\n\n// Recursive solution - Using LONG_MIN anmd LONG_MAX\nclass Solution {\npublic: \n bool solve(TreeNode* root, long min, long max){\n if(root = | prathams29 | NORMAL | 2023-08-28T16:53:49.672894+00:00 | 2023-08-28T16:53:49.672930+00:00 | 1,371 | false | # Code\n```\n// Recursive solution - Using LONG_MIN anmd LONG_MAX\nclass Solution {\npublic: \n bool solve(TreeNode* root, long min, long max){\n if(root == NULL) \n return true;\n \n if(root->val <= min || root->val >= max) \n return false;\n \n return sol... | 12 | 0 | ['Tree', 'Depth-First Search', 'Binary Search Tree', 'Binary Tree', 'C++'] | 1 |
validate-binary-search-tree | ✅Intuitive C++ Solution | Inorder Traversal | intuitive-c-solution-inorder-traversal-b-csv7 | Let\'s connect on Linkedin https://www.linkedin.com/in/arthur-asanaliev/\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- | Arthis_ | NORMAL | 2023-04-07T13:08:38.853462+00:00 | 2023-04-10T16:45:22.674218+00:00 | 4,788 | false | ##### Let\'s connect on Linkedin https://www.linkedin.com/in/arthur-asanaliev/\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> node... | 12 | 0 | ['Binary Search Tree', 'C++'] | 1 |
validate-binary-search-tree | Easy C++ solution | DFS | Recursion | easy-c-solution-dfs-recursion-by-coding_-fgla | Solution via in-order traversal [we need to check whether that returned elements are in ascending order]\n\n\nclass Solution {\npublic:\n long int num = LONG | coding_menance | NORMAL | 2022-10-23T15:48:12.373311+00:00 | 2022-11-01T05:31:26.731665+00:00 | 3,111 | false | # Solution via in-order traversal [we need to check whether that returned elements are in ascending order]\n\n```\nclass Solution {\npublic:\n long int num = LONG_MIN;\n\n bool isValidBST(TreeNode* root) {\n if (!root) return true;\n \n bool ans = isValidBST(root->left);\n \n if... | 12 | 0 | ['Tree', 'Depth-First Search', 'C++'] | 2 |
validate-binary-search-tree | ✔️ 100% Fastest Swift Solution, time: O(n), space: O(n). | 100-fastest-swift-solution-time-on-space-28pu | \n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right | sergeyleschev | NORMAL | 2022-04-08T13:37:06.811342+00:00 | 2022-04-08T13:37:06.811383+00:00 | 981 | false | ```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; sel... | 12 | 0 | ['Swift'] | 2 |
validate-binary-search-tree | Validate Binary Search Tree 4 line compressed code | validate-binary-search-tree-4-line-compr-7opd | \npublic boolean isValidBST(TreeNode root) {\n return isValid(root,Long.MIN_VALUE,Long.MAX_VALUE); \n }\n public boolean isValid(TreeNode roo | ritik26 | NORMAL | 2020-12-16T12:09:38.731827+00:00 | 2020-12-16T12:09:38.731853+00:00 | 705 | false | ```\npublic boolean isValidBST(TreeNode root) {\n return isValid(root,Long.MIN_VALUE,Long.MAX_VALUE); \n }\n public boolean isValid(TreeNode root,long least,long max){\n if(root==null) return true;\n if(root.left!=null&&(root.left.val>=root.val||root.left.val<=least)) return false;\n ... | 12 | 4 | ['Depth-First Search', 'Java'] | 3 |
validate-binary-search-tree | DFS solution easy to understand💪🏻 | dfs-solution-easy-to-understand-by-just_-mgfp | \n def isValidBST(self, root: TreeNode) -> bool:\n self.answer = True\n \n def dfs(root, left, right):\n if root:\n | just_4ina | NORMAL | 2020-09-15T11:43:53.516684+00:00 | 2020-09-15T11:43:53.516747+00:00 | 1,853 | false | ```\n def isValidBST(self, root: TreeNode) -> bool:\n self.answer = True\n \n def dfs(root, left, right):\n if root:\n if left >= root.val or root.val >= right:\n self.answer = False\n return\n dfs(root.left, left, ro... | 12 | 0 | ['Depth-First Search', 'Recursion', 'Python', 'Python3'] | 4 |
validate-binary-search-tree | Python - Simple Solution | python-simple-solution-by-nuclearoreo-e22u | \nclass Solution:\n def isValidBST(self, root: TreeNode) -> bool:\n return self.helper(root, float(\'-inf\'), float(\'inf\'))\n \n def helper(se | nuclearoreo | NORMAL | 2019-08-03T21:57:45.099029+00:00 | 2019-08-03T21:57:45.099068+00:00 | 1,940 | false | ```\nclass Solution:\n def isValidBST(self, root: TreeNode) -> bool:\n return self.helper(root, float(\'-inf\'), float(\'inf\'))\n \n def helper(self, node, minVal, maxVal):\n if node == None:\n return True\n \n if node.val <= minVal or node.val >= maxVal:\n re... | 12 | 1 | ['Python', 'Python3'] | 0 |
validate-binary-search-tree | C# DFS | c-dfs-by-bacon-zcih | \npublic class Solution {\n public bool IsValidBST(TreeNode root) {\n return DFS(root, long.MinValue, long.MaxValue);\n }\n\n private bool DFS(T | bacon | NORMAL | 2019-05-04T03:35:27.768279+00:00 | 2019-05-04T03:35:27.768324+00:00 | 2,267 | false | ```\npublic class Solution {\n public bool IsValidBST(TreeNode root) {\n return DFS(root, long.MinValue, long.MaxValue);\n }\n\n private bool DFS(TreeNode root, long min, long max) {\n if (root == null) return true;\n if (min < root.val && root.val < max) {\n var leftResult = DF... | 12 | 0 | [] | 3 |
validate-binary-search-tree | Swift | swift-by-fuzzybuckbeak-z7op | swift\nfunc isValidBST(_ root: TreeNode?) -> Bool {\n return isBst(root, min: Int.min, max: Int.max)\n}\n \nprivate func isBst(_ node: TreeNode?, min: Int, | fuzzybuckbeak | NORMAL | 2019-02-06T09:16:55.110548+00:00 | 2019-02-06T09:16:55.110593+00:00 | 1,326 | false | ```swift\nfunc isValidBST(_ root: TreeNode?) -> Bool {\n return isBst(root, min: Int.min, max: Int.max)\n}\n \nprivate func isBst(_ node: TreeNode?, min: Int, max: Int) -> Bool {\n\tif node == nil { return true }\n\tif node!.val <= min || node!.val >= max { return false }\n\treturn isBst(node?.left, min: min, max:... | 12 | 0 | [] | 1 |
validate-binary-search-tree | javascript | javascript-by-yinchuhui88-185e | \nvar isValidBST = function(root) {\n if(!root) \n return true\n return dfs(root, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)\n \n func | yinchuhui88 | NORMAL | 2018-12-20T12:39:48.978941+00:00 | 2018-12-20T12:39:48.978980+00:00 | 3,989 | false | ```\nvar isValidBST = function(root) {\n if(!root) \n return true\n return dfs(root, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)\n \n function dfs(root, min, max){\n if(!root) \n return true\n if(root.val <= min || root.val >= max)\n return false\n ret... | 12 | 0 | [] | 3 |
validate-binary-search-tree | Python inorder non-recursive solution, using stack | python-inorder-non-recursive-solution-us-ygsb | class Solution(object):\n def isValidBST(self, root):\n """\n :type root: TreeNode\n :rtype: bool\n """\n | shengwen | NORMAL | 2015-10-24T20:19:01+00:00 | 2015-10-24T20:19:01+00:00 | 2,640 | false | class Solution(object):\n def isValidBST(self, root):\n """\n :type root: TreeNode\n :rtype: bool\n """\n # using inorder - binary search tree will be ascending order\n stack = []\n cur = root\n pre = None\n wh... | 12 | 0 | ['Stack', 'Python'] | 1 |
validate-binary-search-tree | Easy 100% beats. Stack. Python. | easy-100-beats-stack-python-by-einsou-57aj | IntuitionA Binary Search Tree (BST) follows a strict ordering rule:
• All nodes in the left subtree must be less than the current node.
• All nodes in the right | einsou | NORMAL | 2025-03-03T13:53:13.731115+00:00 | 2025-03-03T13:53:13.731115+00:00 | 1,121 | false | # Intuition
A Binary Search Tree (BST) follows a strict ordering rule:
• All nodes in the left subtree must be less than the current node.
• All nodes in the right subtree must be greater than the current node.
Instead of using recursion, we can leverage an iterative DFS approach with a stack.
Each node should satis... | 11 | 0 | ['Python3'] | 0 |
validate-binary-search-tree | Python - Simple Solution | python-simple-solution-by-vvivekyadav-q4f7 | If you got help from this,... Plz Upvote .. it encourage me\n\n# Code\n\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0 | vvivekyadav | NORMAL | 2023-09-23T13:41:38.169834+00:00 | 2023-09-23T13:42:15.917342+00:00 | 1,927 | false | **If you got help from this,... Plz Upvote .. it encourage me**\n\n# Code\n```\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isValidBST(self, ... | 11 | 0 | ['Tree', 'Depth-First Search', 'Binary Search Tree', 'Recursion', 'Binary Tree', 'Python', 'Python3'] | 2 |
validate-binary-search-tree | Best O(N) Solution | best-on-solution-by-kumar21ayush03-9yqj | Approach\nBest Approach\n\n# Complexity\n- Time complexity:\nO(n) \n\n- Space complexity:\nO(h) --> h is height of the BST\n\n# Code\n\n/**\n * Definition for a | kumar21ayush03 | NORMAL | 2023-03-08T12:02:48.718790+00:00 | 2023-03-14T14:47:51.728225+00:00 | 3,031 | false | # Approach\nBest Approach\n\n# Complexity\n- Time complexity:\n$$O(n)$$ \n\n- Space complexity:\n$$O(h)$$ --> h is height of the BST\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullpt... | 11 | 0 | ['C++'] | 1 |
validate-binary-search-tree | ⭐ Simple brute force solution, O(N) ⌛time O(N) 🌌 space. | simple-brute-force-solution-on-time-on-s-d0d9 | Intuition\n Describe your first thoughts on how to solve this problem. \nIf you clearly understand the question, it states that you just need to check whether t | programmer-buddy | NORMAL | 2023-03-03T11:59:38.969979+00:00 | 2023-03-03T11:59:38.970012+00:00 | 2,603 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf you clearly understand the question, it states that you just need to check whether the BST is valid or not, and when we traverse a BST using INORDER, the output stream will be a sorted list.\n\n# Simple Approach\n<!-- Describe your app... | 11 | 0 | ['Binary Search Tree', 'Recursion', 'C++'] | 2 |
validate-binary-search-tree | ✅Short || C++ || Java || PYTHON || Explained Solution✔️ || Beginner Friendly ||🔥 🔥 BY MR CODER | short-c-java-python-explained-solution-b-ngt6 | Please UPVOTE if you LIKE!!\nWatch this video for the better explanation of the code.\nAlso you can SUBSCRIBE \uD83E\uDC83 this channel for the daily leetcode c | mrcoderrm | NORMAL | 2022-09-12T19:04:31.629187+00:00 | 2022-09-12T19:04:31.629231+00:00 | 1,325 | false | **Please UPVOTE if you LIKE!!**\n***Watch this video for the better explanation of the code.***\n**Also you can SUBSCRIBE \uD83E\uDC83 this channel for the daily leetcode challange solution.**\nhttps://www.youtube.com/watch?v=geBeUvcMMwo\n\n**C++**\n```\nclass Solution {\npublic:\n void helper(TreeNode* root, vector... | 11 | 0 | ['C', 'Python', 'Java'] | 2 |
validate-binary-search-tree | Easy C++ Inorder Traversal O(N) | easy-c-inorder-traversal-on-by-venkatng-cs4z | The inorder traversal of a BST is always sorted.\nAlgortihm\n1) Obtain the Inorder traversal of Binary Tree\n2) Check if Inorder traversal is sorted\n3) If sort | venkatng | NORMAL | 2022-01-11T08:28:54.355792+00:00 | 2022-01-11T08:29:42.313525+00:00 | 760 | false | The inorder traversal of a BST is always sorted.\nAlgortihm\n1) Obtain the Inorder traversal of Binary Tree\n2) Check if Inorder traversal is sorted\n3) If sorted then return TRUE\n4) If NOT sorted then return FALSE\n\nInorder Traversal Explained\n {\n return isValidBST(root, null, null);\n }\n \n public boolean isValidBST(Tre | anicol-l | NORMAL | 2020-04-23T23:50:16.064281+00:00 | 2020-04-23T23:51:25.597135+00:00 | 1,523 | false | ```\nclass Solution {\n public boolean isValidBST(TreeNode root) {\n return isValidBST(root, null, null);\n }\n \n public boolean isValidBST(TreeNode root, Integer min, Integer max) {\n if (root == null) \n return true; \n if ((max != null && root.val >= max) || (min != null ... | 11 | 0 | ['Depth-First Search', 'Recursion', 'Java'] | 2 |
validate-binary-search-tree | Output in submit and run code are different | output-in-submit-and-run-code-are-differ-oy5f | I submit my code and got return as wrong answer since it does not pass case [0,-1]. It shows my output is false but it should be true. Then I run code by check | lizyxr | NORMAL | 2015-09-23T23:18:28+00:00 | 2015-09-23T23:18:28+00:00 | 8,009 | false | I submit my code and got return as wrong answer since it does not pass case [0,-1]. It shows my output is false but it should be true. Then I run code by check customized case [0,-1]. It shows my output is true. Is there anything wrong?\n\n # Definition for a binary tree node.\n # class TreeNode(object):\n # ... | 11 | 0 | [] | 5 |
validate-binary-search-tree | Morris Traversal, O(1) space, No recursion, O(n) time with explanation, Java | morris-traversal-o1-space-no-recursion-o-1hbz | // inorder traversal to see if the value is monotonically increased\n // use morris traversal to gain O(1) space, No recursion and O(n) time\n // main ide | mayijie88 | NORMAL | 2015-06-28T19:34:29+00:00 | 2015-06-28T19:34:29+00:00 | 3,278 | false | // inorder traversal to see if the value is monotonically increased\n // use morris traversal to gain O(1) space, No recursion and O(n) time\n // main idea: the key part of tree traversal is how to go back to parent,\n // one way is to use recursion and store parent in function stack,\n // ... | 11 | 0 | ['Java'] | 2 |
validate-binary-search-tree | Simplest logic Inorder should be increasing order: Runtime- 0 ms Beats 100.00% | simplest-logic-inorder-should-be-increas-9qax | ApproachSimplest logic Inorder should be increasing orderComplexity
Time complexity:
0 ms Beats 100.00%
Space complexity:
8.08 MB Beats 7.27%
Code | sushilmaxbhile | NORMAL | 2025-04-01T05:43:33.676429+00:00 | 2025-04-01T05:46:03.421125+00:00 | 616 | false | # Approach
Simplest logic Inorder should be increasing order
# Complexity
- Time complexity:
0 ms Beats 100.00%
- Space complexity:
8.08 MB Beats 7.27%
# Code
```golang []
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func isV... | 10 | 2 | ['Go'] | 1 |
validate-binary-search-tree | Pattern easy understanding | pattern-easy-understanding-by-dixon_n-30x3 | Intuition\n\nupdate the min and max values range for everynode follow BST property of left and right values.\n\n# Complexity \n- Time complexity: O(n)\n\n- Spac | Dixon_N | NORMAL | 2024-05-13T04:50:16.410010+00:00 | 2024-05-13T04:50:16.410055+00:00 | 1,276 | false | # Intuition\n\nupdate the min and max values **range for everynode** follow BST property of left and right values.\n\n# Complexity \n- Time complexity: O(n)\n\n- Space complexity: O(n)\n# Pattern\n[1448. Count Good Nodes in Binary Tree](https://leetcode.com/problems/count-good-nodes-in-binary-tree/solutions/3978785/sim... | 10 | 0 | ['Tree', 'Binary Search Tree', 'Recursion', 'Binary Tree', 'Java'] | 2 |
validate-binary-search-tree | C++ | 6 different solutions | recursive / iteratively / in-order traversal check previous / ... | c-6-different-solutions-recursive-iterat-deu4 | I came up with a few different approaches. Please let me know if you came up with another idea.Solution 1: recursive with numeric limitsSolution 2: recursive wi | heder | NORMAL | 2022-08-11T07:13:40.352620+00:00 | 2025-03-03T22:28:11.821527+00:00 | 401 | false | I came up with a few different approaches. Please let me know if you came up with another idea.
**Solution 1: recursive with numeric limits**
```
bool isValidBST(TreeNode* root) {
return isValidBST(root, numeric_limits<long>::min(), numeric_limits<long>::max());
}
bool isValidBST(TreeNode* n... | 10 | 1 | ['Recursion', 'C', 'Iterator'] | 0 |
validate-binary-search-tree | C++ long long man | c-long-long-man-by-midnightsimon-yo3s | if you go left, set bounds to min to root->val\n2. if you go right, set boudns to root->val to max\n3. use long long to get away from overflow and underflows\n4 | midnightsimon | NORMAL | 2022-08-11T01:27:00.424163+00:00 | 2022-08-11T01:27:00.424211+00:00 | 1,290 | false | 1. if you go left, set bounds to min to root->val\n2. if you go right, set boudns to root->val to max\n3. use long long to get away from overflow and underflows\n**4. check out the twitch channel. Link in profile.**\n```\nclass Solution { \n bool dfs(TreeNode* root, long long mn, long long mx) {\n if(!root)... | 10 | 1 | [] | 3 |
validate-binary-search-tree | C++ clear recursive solution without using longlong/double | c-clear-recursive-solution-without-using-mjmg | \nclass Solution {\npublic:\n bool isValidBST(TreeNode* root, TreeNode* nmin = nullptr, TreeNode* nmax = nullptr) {\n if(!root) \n return t | freeyy | NORMAL | 2019-07-27T12:10:59.441616+00:00 | 2019-07-27T12:11:35.096670+00:00 | 1,806 | false | ```\nclass Solution {\npublic:\n bool isValidBST(TreeNode* root, TreeNode* nmin = nullptr, TreeNode* nmax = nullptr) {\n if(!root) \n return true;\n if(nmin && root->val <= nmin->val)\n return false;\n if(nmax && root->val >= nmax->val)\n return false;\n r... | 10 | 1 | ['Recursion', 'C++'] | 3 |
validate-binary-search-tree | Easy to Understand - Concise - C++ | easy-to-understand-concise-c-by-lc00703-69ko | Code\n\nclass Solution {\npublic:\n vector<int> nodes;\n void inorder(TreeNode* root) {\n if (root->left) inorder(root->left);\n nodes.push_ | lc00703 | NORMAL | 2023-04-21T12:39:45.639915+00:00 | 2023-04-21T12:39:45.639963+00:00 | 8,065 | false | # Code\n```\nclass Solution {\npublic:\n vector<int> nodes;\n void inorder(TreeNode* root) {\n if (root->left) inorder(root->left);\n nodes.push_back(root->val);\n if (root->right) inorder(root->right);\n }\n bool isValidBST(TreeNode* root) {\n inorder(root);\n for (int i ... | 9 | 0 | ['C++'] | 0 |
validate-binary-search-tree | Python solution with linear time complexity. 100% working! | python-solution-with-linear-time-complex-upth | \n def dfs(lower,upper,node):\n if not node:\n return True\n elif node.val<=lower or node.val>=upper:\n | enigmatic__soul | NORMAL | 2023-01-28T18:39:00.395973+00:00 | 2023-01-28T18:39:00.396017+00:00 | 2,242 | false | \n def dfs(lower,upper,node):\n if not node:\n return True\n elif node.val<=lower or node.val>=upper:\n return False\n else:\n return dfs(lower,node.val,node.left) and dfs(node.val,upper,node.right)\n return dfs(float(\'-inf\'),... | 9 | 0 | ['Python'] | 0 |
validate-binary-search-tree | Optimized approach | optimized-approach-by-nikhil_mane-yq1s | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | nikhil_mane | NORMAL | 2023-01-02T02:11:57.929211+00:00 | 2023-01-02T02:11:57.929255+00:00 | 2,842 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 9 | 0 | ['C++'] | 0 |
validate-binary-search-tree | Python - Recursion and Recursive stack space + O(1) space | python-recursion-and-recursive-stack-spa-v5k2 | Without using a list just use prev variable to store the previous node value and check if the Tree nodes are in ascending order during the inorder traversal. Yo | Thiru_Mv | NORMAL | 2022-08-01T22:23:57.545318+00:00 | 2022-08-01T22:29:14.480588+00:00 | 522 | false | Without using a list just use prev variable to store the previous node value and check if the Tree nodes are in ascending order during the inorder traversal. You dont have to create extra space for list.\n \n def isValidBST(self, root):\n """\n :type root: TreeNode\n :rtype: bool\n """... | 9 | 0 | ['Recursion', 'Python'] | 0 |
validate-binary-search-tree | Python recursive and iterative solutions | python-recursive-and-iterative-solutions-8qpe | Recursive solution:\n\nclass Solution:\n def isValidBST(self, root: Optional[TreeNode]) -> bool:\n def helper(root, min_val=float("-inf"), max_val=flo | PythonicLava | NORMAL | 2022-06-26T00:18:49.921198+00:00 | 2022-06-26T00:18:49.921225+00:00 | 1,508 | false | Recursive solution:\n```\nclass Solution:\n def isValidBST(self, root: Optional[TreeNode]) -> bool:\n def helper(root, min_val=float("-inf"), max_val=float("inf")):\n if root is None:\n return True\n \n return (min_val < root.val < max_val and helper(root.left, ... | 9 | 1 | ['Recursion', 'Iterator', 'Python', 'Python3'] | 1 |
validate-binary-search-tree | Neat Java Recursive Solution | neat-java-recursive-solution-by-jayomg-5zgf | java\nclass Solution {\n public boolean isValidBST(TreeNode root) {\n return isValidBST(root, null, null);\n }\n \n public boolean isValidBST | jayomg | NORMAL | 2019-01-31T00:50:49.750231+00:00 | 2019-01-31T00:50:49.750294+00:00 | 759 | false | ``` java\nclass Solution {\n public boolean isValidBST(TreeNode root) {\n return isValidBST(root, null, null);\n }\n \n public boolean isValidBST(TreeNode x, TreeNode min, TreeNode max) {\n if (x == null) return true;\n if (max != null && x.val >= max.val) return false;\n if (min... | 9 | 0 | [] | 2 |
validate-binary-search-tree | Java solution after adding test cases | java-solution-after-adding-test-cases-by-qfuc | Actually, not too much needs to be changed if you got AC code when extra test cases are not added. The only difference is add if-else condition for node's value | chase1991 | NORMAL | 2014-11-16T23:42:35+00:00 | 2014-11-16T23:42:35+00:00 | 2,562 | false | Actually, not too much needs to be changed if you got AC code when extra test cases are not added. The only difference is add if-else condition for node's value equals INT_MAX and INT_MIN. \n\n public class Solution {\n public boolean isValidBST(TreeNode root) {\n if (root == null) {\n ... | 9 | 0 | [] | 4 |
validate-binary-search-tree | ✅💯🔥Simple Code🚀📌|| 🔥✔️Easy to understand🎯 || 🎓🧠Beats 100%🔥|| Beginner friendly💀💯 | simple-code-easy-to-understand-beats-100-7pxb | Solution tuntun mosi ki photo ke baad hai. Scroll Down\n\n\n# Code\njava []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int | atishayj4in | NORMAL | 2024-08-20T21:07:57.351801+00:00 | 2024-08-20T21:07:57.351832+00:00 | 1,792 | false | Solution tuntun mosi ki photo ke baad hai. Scroll Down\n\n\n# Code\n```java []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * ... | 8 | 1 | ['Tree', 'Depth-First Search', 'Binary Search Tree', 'C', 'Binary Tree', 'Python', 'C++', 'Java', 'JavaScript'] | 2 |
validate-binary-search-tree | 0ms||Easy||JAVA✌ | 0mseasyjava-by-tamosakatwa-guba | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | tamosakatwa | NORMAL | 2023-01-08T15:04:33.317081+00:00 | 2023-01-08T15:04:33.317119+00:00 | 2,180 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 8 | 1 | ['Java'] | 1 |
validate-binary-search-tree | ✅Easiest 3 Lines Recursive Solution✅ | easiest-3-lines-recursive-solution-by-yo-beks | Easiest 3 lines recursive solution using C++.\nSelf Explanatory\n\n bool isBST(TreeNode* root,long min, long max){\n if(root==NULL) return true;\n | yogesh3_14 | NORMAL | 2022-08-12T04:53:46.203711+00:00 | 2022-08-15T00:19:20.691984+00:00 | 368 | false | **Easiest 3 lines recursive solution using C++.\nSelf Explanatory**\n```\n bool isBST(TreeNode* root,long min, long max){\n if(root==NULL) return true;\n if(root->val <= min || root->val >= max) return false;\n return isBST(root->left,min,root->val) and isBST(root->right,root->val,max);\n }\n... | 8 | 0 | ['Binary Search Tree', 'Recursion', 'C'] | 0 |
validate-binary-search-tree | 🗓️ Daily LeetCoding Challenge August, Day 11 | daily-leetcoding-challenge-august-day-11-4w7x | This problem is the Daily LeetCoding Challenge for August, Day 11. Feel free to share anything related to this problem here! You can ask questions, discuss what | leetcode | OFFICIAL | 2022-08-11T00:00:27.674623+00:00 | 2022-08-11T00:00:27.674698+00:00 | 7,767 | false | This problem is the Daily LeetCoding Challenge for August, Day 11.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please cr... | 8 | 0 | [] | 71 |
validate-binary-search-tree | Java Recursive Approach (100% Faster) | java-recursive-approach-100-faster-by-ni-8t0z | \n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n | nikitajuneja1 | NORMAL | 2022-03-07T16:58:57.366456+00:00 | 2022-03-07T16:59:46.302363+00:00 | 770 | false | ```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = l... | 8 | 0 | ['Depth-First Search', 'Recursion', 'Java'] | 0 |
validate-binary-search-tree | C++ Easy Solution | Recursion | c-easy-solution-recursion-by-amittiwari0-3jco | \nclass Solution {\npublic:\n \n bool solve(TreeNode* root, long long int min,long long int max){\n if(!root)return true;\n \n if(roo | amittiwari04 | NORMAL | 2021-11-12T05:53:33.029396+00:00 | 2021-11-12T05:53:33.029443+00:00 | 1,259 | false | ```\nclass Solution {\npublic:\n \n bool solve(TreeNode* root, long long int min,long long int max){\n if(!root)return true;\n \n if(root->val>=max || root->val<=min)return false;\n \n return solve(root->left,min,root->val) and solve(root->right,root->val,max);\n }\n \n ... | 8 | 0 | ['Recursion', 'C', 'C++'] | 1 |
validate-binary-search-tree | Python Morris O(1) space approach | python-morris-o1-space-approach-by-dynam-7wzk | For when the Interviewer asks for a space optimal i.e. O(1) BST traversal as a follow-up question.\nThis is standard in-order morris traversal as a generator. T | dynamicstardust | NORMAL | 2021-03-27T03:03:36.686436+00:00 | 2021-03-28T05:38:16.215480+00:00 | 301 | false | For when the Interviewer asks for a space optimal i.e. O(1) BST traversal as a follow-up question.\nThis is standard in-order morris traversal as a generator. The values yielded by Morris generator with BST should be strictly increasing in this problem.\n\n```\nclass Solution:\n def isValidBST(self, root: TreeNode) ... | 8 | 0 | ['Python'] | 1 |
validate-binary-search-tree | 🔥BEATS 💯 % 🎯 |✨SUPER EASY BEGINNERS 👏 | beats-super-easy-beginners-by-codewithsp-u9rg | IntuitionThe problem requires us to determine whether a given binary tree is a valid binary search tree (BST). A valid BST must satisfy the following conditions | CodeWithSparsh | NORMAL | 2025-01-20T15:56:47.577585+00:00 | 2025-01-20T15:58:01.451327+00:00 | 1,409 | false | 
---

---
## Intuition
The problem requires us to determine whether a given binary... | 7 | 0 | ['Tree', 'Depth-First Search', 'Binary Search Tree', 'C', 'Binary Tree', 'C++', 'Java', 'Python3', 'JavaScript', 'Dart'] | 2 |
watering-plants-ii | Straightforward | straightforward-by-votrubac-z18w | I am scared of Alice and Bob problems. But this one, luckily, is benign (except for a lengthy description).\n\nThe one thing to realize is that, if the array si | votrubac | NORMAL | 2021-12-12T04:02:05.024729+00:00 | 2021-12-12T04:19:08.328164+00:00 | 2,827 | false | I am scared of Alice and Bob problems. But this one, luckily, is benign (except for a lengthy description).\n\nThe one thing to realize is that, if the array size is odd, Alice or Bob can water it if they have water, or one of them needs to refill otherwise.\n\n**C++**\n```cpp\nint minimumRefill(vector<int>& plants, in... | 49 | 6 | [] | 7 |
watering-plants-ii | [C++/Java/Python] O(N) Easy Intuition + Image Explanation | cjavapython-on-easy-intuition-image-expl-f0ly | As it\'s given in problem statement\n> Alice waters the plants in order from left to right, starting from the 0th plant. Bob waters the plants in order from rig | sachuverma | NORMAL | 2021-12-12T04:03:27.738493+00:00 | 2021-12-12T05:15:22.077948+00:00 | 2,487 | false | As it\'s given in problem statement\n> Alice waters the plants in order from **left to right**, starting from the `0th` plant. Bob waters the plants in order from **right to left**, starting from the `(n - 1)th` plant. They begin watering the plants **simultaneously**.\n\n\n# Intuition:\n\nWe need to keep two pointer i... | 27 | 2 | [] | 8 |
watering-plants-ii | Java | Simple Detailed Explanation || ⏲ 3ms100% faster || 2 Pointer | java-simple-detailed-explanation-3ms100-qa7c8 | \u2714 Solution: 2 Pointer | Beats 100 %, 3ms \u23F2\n-----\n Alice start from i=0\n Bob start from j=n-1 index , n size of array\n Both Alice and bob move one | abhi9720 | NORMAL | 2021-12-12T16:29:46.313235+00:00 | 2022-02-21T15:19:47.218783+00:00 | 1,203 | false | ### \u2714 ***Solution: 2 Pointer*** | Beats 100 %, 3ms \u23F2\n-----\n* Alice start from i=0\n* Bob start from j=n-1 index , n size of array\n* Both Alice and bob move one step , Now all cases possible in their movement\n\t* **Case 1 :** Alice and Bob both have sufficient water , they will water plant \n\t* **Case 2... | 19 | 1 | ['Two Pointers', 'Java'] | 3 |
watering-plants-ii | [Python3] 2 pointers | python3-2-pointers-by-ye15-hikm | Please check out this commit for solutions of weekly 271. \n\n\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) | ye15 | NORMAL | 2021-12-12T04:02:06.535814+00:00 | 2021-12-12T18:43:10.904122+00:00 | 965 | false | Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/f57038d6cca9ccb356a137b3af67fba615a067dd) for solutions of weekly 271. \n\n```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n ans = 0 \n lo, hi = 0, len(plants)-1\n ... | 10 | 0 | ['Python3'] | 2 |
watering-plants-ii | C++ solutions | c-solutions-by-infox_92-4m9w | \nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int N = plants.size(), i = 0, j = N - 1;\n | Infox_92 | NORMAL | 2022-11-20T06:29:40.500895+00:00 | 2022-11-20T06:29:40.500940+00:00 | 497 | false | ```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int N = plants.size(), i = 0, j = N - 1;\n \n if (N == 1) return 0;\n \n int totalFills = 0; \n int aliceCan = capacityA, bobCan = capacityB; \n \n // Iter... | 9 | 0 | ['Dynamic Programming', 'C', 'C++'] | 0 |
watering-plants-ii | C++ Two Pointers | c-two-pointers-by-lzl124631x-pmyy | See my latest update in repo LeetCode\n## Solution 1. Two Pointers\n\ncpp\n// OJ: https://leetcode.com/contest/weekly-contest-271/problems/watering-plants-ii/\n | lzl124631x | NORMAL | 2021-12-12T04:01:16.168236+00:00 | 2021-12-12T04:17:57.509404+00:00 | 899 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n## Solution 1. Two Pointers\n\n```cpp\n// OJ: https://leetcode.com/contest/weekly-contest-271/problems/watering-plants-ii/\n// Author: github.com/lzl124631x\n// Time: O(N)\n// Space: O(1)\nclass Solution {\npublic:\n int minimumRefill(v... | 8 | 3 | [] | 1 |
watering-plants-ii | [JAVA/C++] Easy solution explained with comments | javac-easy-solution-explained-with-comme-ezft | JAVA:\n\n\'\'\'class Solution {\n\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n\t\n\t\t//number of refills\n int re = 0;\ | hetvigarg | NORMAL | 2021-12-12T04:06:19.408738+00:00 | 2021-12-12T05:14:10.660512+00:00 | 673 | false | **JAVA:**\n\n\'\'\'class Solution {\n\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n\t\n\t\t//number of refills\n int re = 0;\n \n int a = capacityA, b = capacityB;\n int n = plants.length;\n \n\t\tif(n==1) return 0;\n\t\t\n int j=n-1;\n fo... | 6 | 0 | ['Two Pointers', 'C', 'Java'] | 1 |
watering-plants-ii | c++ solution | c-solution-by-manishya1669-7j53 | smjh\n\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int i=0;\n int j=plants.size()-1;\n int a=capacityA;\n | manishya1669 | NORMAL | 2022-01-05T07:22:51.941471+00:00 | 2022-01-05T07:22:51.941513+00:00 | 307 | false | smjh\n```\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int i=0;\n int j=plants.size()-1;\n int a=capacityA;\n int b=capacityB;\n int ans=0;\n while(i<j){\n if(plants[i]<=a){\n a-=plants[i];\n \n }... | 4 | 0 | ['C'] | 0 |
watering-plants-ii | JAVA || Very Easy to Understand | java-very-easy-to-understand-by-kannan_2-o9n2 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTwo Pointer\n\n# Complexity\n- Time complexity:\nO(log n)\n\n- Space comp | kannan_27 | NORMAL | 2023-05-14T01:35:54.725940+00:00 | 2023-05-14T01:35:54.725970+00:00 | 252 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTwo Pointer\n\n# Complexity\n- Time complexity:\nO(log n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public int minimumRefill(int[] p,int A, int B) {\n int n=p.length;\n int x=A,y=B;\n ... | 2 | 0 | ['Two Pointers', 'Java'] | 1 |
watering-plants-ii | C++ || Two Pointer || O(N) | c-two-pointer-on-by-neeraj_jm-9zhi | ```\nclass Solution {\npublic:\n int minimumRefill(vector& plants, int capacityA, int capacityB) {\n int i = 0;\n int j = plants.size() - 1;\n | neeraj_jm | NORMAL | 2022-10-24T07:23:37.327700+00:00 | 2022-10-24T07:23:37.327724+00:00 | 526 | false | ```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int i = 0;\n int j = plants.size() - 1;\n int tot_refill = 0;\n int capA = capacityA;\n int capB = capacityB;\n while(i<j){\n \n if(plants[i]<=capa... | 2 | 0 | ['Two Pointers', 'C', 'C++'] | 0 |
watering-plants-ii | java solution 5ms || simple and easy | java-solution-5ms-simple-and-easy-by-sis-g4d2 | //please upvote if you like my approach\n\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n int count=0;\n | Sisvanth | NORMAL | 2022-01-25T12:43:22.747855+00:00 | 2022-01-25T12:43:22.747886+00:00 | 282 | false | **//please upvote if you like my approach**\n```\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n int count=0;\n int c1=capacityA,c2=capacityB;\n for(int start=0,end=plants.length-1;start<=plants.length/2&&end>=plants.length/2;start++,end--){\n ... | 2 | 0 | ['Java'] | 0 |
watering-plants-ii | ✔Simple O(N) Two-Pointer. | simple-on-two-pointer-by-sahilanower-ex8y | \nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int n=plants.size();\n int alice=0,bob=n | SahilAnower | NORMAL | 2021-12-24T17:08:41.610023+00:00 | 2021-12-24T17:08:41.610063+00:00 | 139 | false | ```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int n=plants.size();\n int alice=0,bob=n-1,temp1=capacityA,temp2=capacityB;\n int count=0;\n \n while(alice<bob){\n if(temp1<plants[alice]){\n count++... | 2 | 0 | ['Two Pointers'] | 0 |
watering-plants-ii | (C++), easy to understand | c-easy-to-understand-by-priyanshupundhir-cm3x | \n\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) \n {\n int n=plants.size();\n int n1=capacityA;\n | PriyanshuPundhir | NORMAL | 2021-12-12T11:30:20.200835+00:00 | 2021-12-12T11:30:20.200865+00:00 | 246 | false | ```\n\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) \n {\n int n=plants.size();\n int n1=capacityA;\n int n2=capacityB;\n int i=0;\n int j=n-1;\n int count=0;\n while(i<=j)\n {\n if(i==j)\n {\n ... | 2 | 0 | ['Two Pointers', 'C', 'C++'] | 0 |
watering-plants-ii | C++ EASY TWO_POINTERS | c-easy-two_pointers-by-the_expandable-iui1 | ```\nclass Solution {\npublic:\n #define ll long long int \n int minimumRefill(vector& p, int ca, int cb) {\n int n = p.size();\n int i = 0 | the_expandable | NORMAL | 2021-12-12T08:35:14.445800+00:00 | 2021-12-12T08:35:14.445826+00:00 | 78 | false | ```\nclass Solution {\npublic:\n #define ll long long int \n int minimumRefill(vector<int>& p, int ca, int cb) {\n int n = p.size();\n int i = 0 ; int j = n-1;\n ll a = ca ;\n ll b = cb ; \n ll ans=0;\n while(i <= j)\n {\n //cout<<ca<<" "<<cb<<endl;\n ... | 2 | 0 | [] | 0 |
watering-plants-ii | C++ || Two pointers || Easy | c-two-pointers-easy-by-rajdeep_nagar-tn9g | \nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int A, int B) {\n \n int x=A,y=B;\n int n=plants.size();\n int i=0 | Rajdeep_Nagar | NORMAL | 2021-12-12T04:23:16.038414+00:00 | 2021-12-12T04:24:53.055466+00:00 | 125 | false | ```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int A, int B) {\n \n int x=A,y=B;\n int n=plants.size();\n int i=0,j=n-1;\n int c=0;\n \n while(i<=j){\n if(i==j){\n if(A< plants[i] && B < plants[i])\n c++;\n }\n ... | 2 | 1 | ['Two Pointers', 'C++'] | 2 |
watering-plants-ii | Just Brute Force !! | just-brute-force-by-rishabh_devbanshi-9h46 | \nint minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n typedef long long ll;\n \n ll n = size(plants);\n ll cnt | rishabh_devbanshi | NORMAL | 2021-12-12T04:22:46.544322+00:00 | 2021-12-12T04:22:46.544351+00:00 | 236 | false | ```\nint minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n typedef long long ll;\n \n ll n = size(plants);\n ll cnt = 0;\n \n ll al = 0 , bob = n-1;\n \n ll tal = capacityA , tbob = capacityB;\n \n while(al < bob)\n {\n ... | 2 | 0 | [] | 2 |
watering-plants-ii | Two Pointer Solution | two-pointer-solution-by-kartikaydhingra-gujo | \nint sum = 0;\n int alice = capacityA;\n int bob = capacityB;\n for(int i = 0, j = plants.length - 1; i <= j; i++, j--){\n if(i | kartikaydhingra | NORMAL | 2021-12-12T04:02:36.856758+00:00 | 2021-12-12T04:02:36.856796+00:00 | 144 | false | ```\nint sum = 0;\n int alice = capacityA;\n int bob = capacityB;\n for(int i = 0, j = plants.length - 1; i <= j; i++, j--){\n if(i == j){\n if(alice >= bob){\n if(alice >= plants[i]){\n alice -= plants[i];\n ... | 2 | 0 | ['Array', 'Two Pointers', 'Java'] | 0 |
watering-plants-ii | Java easy | o(n) | two pointer | java-easy-on-two-pointer-by-xavi_an-md4k | ```\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n int cA = capacityA;\n int cB = capacityB;\n | xavi_an | NORMAL | 2021-12-12T04:01:59.758141+00:00 | 2021-12-12T04:03:04.295266+00:00 | 74 | false | ```\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n int cA = capacityA;\n int cB = capacityB;\n int a=0;\n int b=plants.length-1;\n int refill = 0;\n while(a < b){\n if(cA >= plants[a]){\n cA -= plants[a]... | 2 | 1 | [] | 0 |
watering-plants-ii | C++ | two pointer | with explanation | c-two-pointer-with-explanation-by-aman28-qclq | Explanation:-\n1. This is a two pointer problem \n2. Start watering the plants as said from both the ends ,when there is insufficient water then refill the can. | aman282571 | NORMAL | 2021-12-12T04:00:51.872480+00:00 | 2021-12-12T04:00:51.872514+00:00 | 211 | false | **Explanation:-**\n1. This is a **two pointer problem** \n2. Start watering the plants as said from both the ends ,when there is ```insufficient water then refill the can```.\n3. If we have even number of plants then ```alice and bob will water equal number of plants(n/2)```.\n4. If we have odd number of plants then fo... | 2 | 1 | ['C'] | 0 |
watering-plants-ii | Functions ka sahi istemaal koi iss solution se sekhai :))) #best solution so far | functions-ka-sahi-istemaal-koi-iss-solut-9x3g | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Mohd-Arish-Khan | NORMAL | 2025-03-27T17:40:22.921303+00:00 | 2025-03-27T17:40:22.921303+00:00 | 18 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['C++'] | 1 |
watering-plants-ii | two pointers | two-pointers-by-alokitkapoor-hr6g | Intuitionimulate Alice watering from the left and Bob from the right, refilling when needed, and handle the middle plant separately if they meet.ApproachTwo Poi | Alokitkapoor | NORMAL | 2025-02-27T14:26:30.186668+00:00 | 2025-02-27T14:26:30.186668+00:00 | 50 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
imulate Alice watering from the left and Bob from the right, refilling when needed, and handle the middle plant separately if they meet.
# Approach
<!-- Describe your approach to solving the problem. -->
Two Pointers: Use al (Alice) starti... | 1 | 0 | ['C++'] | 1 |
watering-plants-ii | C++ || Beats 61% || 2 pointer | c-beats-61-2-pointer-by-manral_0203-156e | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Manral_0203 | NORMAL | 2024-08-05T16:08:12.953954+00:00 | 2024-08-05T16:12:44.517457+00:00 | 34 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
watering-plants-ii | Easy C++ solution | easy-c-solution-by-nehagupta_09-epnz | \n\n# Code\n\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int capA=capacityA;\n int ca | NehaGupta_09 | NORMAL | 2024-07-07T12:44:15.032812+00:00 | 2024-07-07T12:44:15.032834+00:00 | 27 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int capA=capacityA;\n int capB=capacityB;\n int alice=0;\n int bob=plants.size()-1;\n int ans=0;\n while(alice<bob)\n {\n if(plants[alice]<... | 1 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
watering-plants-ii | EASY AND BASIC SOLUTION ✅✅ | easy-and-basic-solution-by-coder_96677-jfsa | \n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int cap | Coder_96677 | NORMAL | 2023-08-25T11:23:07.607765+00:00 | 2023-08-25T11:23:07.607782+00:00 | 374 | false | \n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int n = plants.size();\n int count =0;\n int start =0;\n int end =n-1;\n int aliceCC = capacity... | 1 | 0 | ['C++'] | 0 |
watering-plants-ii | Two pointer approach | two-pointer-approach-by-teenuburi-x7wo | \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\n func minimumRefill(_ plants: [Int], _ capacityA: Int, | teenuburi | NORMAL | 2023-08-25T08:45:26.702494+00:00 | 2023-08-25T08:45:26.702517+00:00 | 160 | false | \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n func minimumRefill(_ plants: [Int], _ capacityA: Int, _ capacityB: Int) -> Int {\n var ans = 0\n var i = 0\n var aliceWater = capacityA\n var bobWater = capacityB\n var j = pl... | 1 | 0 | ['Swift'] | 0 |
watering-plants-ii | 🔥🔥🔥C++ | super easy | clean code | two pointers | beats 100% runtime🔥🔥🔥 | c-super-easy-clean-code-two-pointers-bea-drbl | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Algo-Messihas | NORMAL | 2023-08-16T16:52:16.483026+00:00 | 2023-08-16T16:57:14.657671+00:00 | 58 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
watering-plants-ii | Recursion Solution || Java || Easy to Understand | recursion-solution-java-easy-to-understa-oihe | \n# Approach\n\n---\n> Two Pointers + Recursion\n\n- Two pointers denoting respective positions of Alice and Bob.\n\n- Whenever they run out of water, their can | virendras996 | NORMAL | 2023-07-12T15:56:30.902029+00:00 | 2023-07-12T15:57:07.897551+00:00 | 9 | false | \n# Approach\n\n---\n> Two Pointers + Recursion\n\n- Two pointers denoting respective positions of Alice and Bob.\n\n- Whenever they run out of water, their cans are refilled with the original water capacity.\n\n- Refilling is being tracked and stored in **count**.\n\n---\n\n\n\n\n# Code\n```\nclass Solution {\n\n p... | 1 | 0 | ['Two Pointers', 'Recursion', 'Java'] | 0 |
watering-plants-ii | Straightforward C++ solution || Clean and simple code || O(N) time complexity | straightforward-c-solution-clean-and-sim-9qjg | Code\n\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int n = plants.size(), i = 0, j = n-1, A | prathams29 | NORMAL | 2023-07-02T04:21:01.051052+00:00 | 2023-07-02T04:23:01.802612+00:00 | 191 | false | # Code\n```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int n = plants.size(), i = 0, j = n-1, A = capacityA, B = capacityB, count = 0;\n while(i<=j)\n {\n if(A>=plants[i]) \n A -= plants[i++];\n else{... | 1 | 0 | ['C++'] | 0 |
watering-plants-ii | Simple C++ Solution || 2 Pointer Approach || Time - O(N) || Space - O(1) | simple-c-solution-2-pointer-approach-tim-8qsu | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | astro-here | NORMAL | 2023-05-12T06:54:00.190378+00:00 | 2023-05-12T06:54:00.190418+00:00 | 28 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n O(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O... | 1 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
watering-plants-ii | Easy & Simple Solution | C++ | easy-simple-solution-c-by-shekhar_k_s-jnky | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Shekhar_k_s | NORMAL | 2023-02-21T04:48:54.925341+00:00 | 2023-02-21T04:48:54.925376+00:00 | 282 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, ... | 1 | 0 | ['C++'] | 0 |
watering-plants-ii | Two pointer Approach | two-pointer-approach-by-nikhil240808-m9aj | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nif plants.length i.e n is even they do not meet they will crossover each | nikhil240808 | NORMAL | 2023-01-23T15:48:16.490843+00:00 | 2023-01-23T15:48:16.490898+00:00 | 320 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nif plants.length i.e n is even they do not meet they will crossover each other otherwise they will meet at the middle which is last iteration check if any one of them has sufficient water then continue otherwise increment re... | 1 | 0 | ['Java'] | 0 |
watering-plants-ii | Python Two Pointers | python-two-pointers-by-shtanriverdi-vd2s | \nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n n = len(plants)\n \n alice = 0\ | shtanriverdi | NORMAL | 2022-11-25T14:16:55.809572+00:00 | 2022-11-25T14:16:55.809607+00:00 | 63 | false | ```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n n = len(plants)\n \n alice = 0\n bob = n - 1\n \n alicesCan = capacityA\n bobsCan = capacityB\n \n answer = 0 \n while alice < bob:\... | 1 | 0 | ['Two Pointers', 'Python'] | 0 |
watering-plants-ii | Very Simple Java Solution | very-simple-java-solution-by-sanyamjain7-40xb | \nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n int n = plants.length, ai = 0, bi = n - 1, ac = capacity | Sanyamjain77 | NORMAL | 2022-09-23T18:23:34.024890+00:00 | 2022-09-23T18:23:34.024929+00:00 | 281 | false | ```\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n int n = plants.length, ai = 0, bi = n - 1, ac = capacityA, bc = capacityB, c = 0;\n // ai is alice\'s current index and bi for bob. Same for capacity\n\t\t\n while(ai < bi){\n\t\t\t// If there is not... | 1 | 0 | ['Java'] | 0 |
watering-plants-ii | C++||Two Pointers||Easy to Understand | ctwo-pointerseasy-to-understand-by-retur-1moa | ```\nclass Solution {\npublic:\n int minimumRefill(vector& plants, int capacityA, int capacityB) \n {\n int i = 0, j = plants.size() - 1, canA = ca | return_7 | NORMAL | 2022-09-03T14:21:25.380615+00:00 | 2022-09-03T14:21:25.380645+00:00 | 190 | false | ```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) \n {\n int i = 0, j = plants.size() - 1, canA = capacityA, canB = capacityB, res = 0;\n while (i < j) {\n res += (canA < plants[i]) + (canB < plants[j]);\n canA = canA < plants... | 1 | 0 | ['Two Pointers', 'C'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.