diff --git a/(152)MaximumProductSubarray.cpp b/(152)MaximumProductSubarray.cpp deleted file mode 100644 index 40de9b7..0000000 --- a/(152)MaximumProductSubarray.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - int maxProduct(vector& nums) { - - int i; - int maxi=nums[0], mini=nums[0]; - int ans = nums[0]; - - for(i=1;i twoSum(vector& nums, int target) { - vector v; - unordered_map m; - for(int i=0;ires) - { - string temp=s.substr(i-dp[i][j],dp[i][j]); - string rev=temp; - reverse(rev.begin(),rev.end()); - if(temp==rev){ //check if common substring is palindromic or not - ans=temp; - cout << ans << endl; - res=dp[i][j]; - } - - } - } - - } - - // for(int i=0;i<=n;i++){ - // for(int j=0;j<=n;j++){ - // cout << dp[i][j] << " "; - // } - // cout << endl; - // } - return ans; - } -}; \ No newline at end of file diff --git a/0005-longest-palindromic-substring/README.md b/0005-longest-palindromic-substring/README.md deleted file mode 100644 index 09ad25e..0000000 --- a/0005-longest-palindromic-substring/README.md +++ /dev/null @@ -1,26 +0,0 @@ -

5. Longest Palindromic Substring

Medium


Given a string s, return the longest palindromic substring in s.

- -

A string is called a palindrome string if the reverse of that string is the same as the original string.

- -

 

-

Example 1:

- -
Input: s = "babad"
-Output: "bab"
-Explanation: "aba" is also a valid answer.
-
- -

Example 2:

- -
Input: s = "cbbd"
-Output: "bb"
-
- -

 

-

Constraints:

- -
    -
  • 1 <= s.length <= 1000
  • -
  • s consist of only digits and English letters.
  • -
-
\ No newline at end of file diff --git a/0007-reverse-integer/0007-reverse-integer.cpp b/0007-reverse-integer/0007-reverse-integer.cpp deleted file mode 100644 index 7ff2186..0000000 --- a/0007-reverse-integer/0007-reverse-integer.cpp +++ /dev/null @@ -1,18 +0,0 @@ -class Solution { -public: - int reverse(int n) { - int rev = 0; - - while(n !=0) { - - if( (rev > INT_MAX/10) || (rev < INT_MIN/10) ){ - return 0; - } - - rev = (rev * 10) + (n % 10); - n /= 10; - } - - return rev; - } -}; \ No newline at end of file diff --git a/0007-reverse-integer/README.md b/0007-reverse-integer/README.md deleted file mode 100644 index db5afe4..0000000 --- a/0007-reverse-integer/README.md +++ /dev/null @@ -1,30 +0,0 @@ -

7. Reverse Integer

Medium


Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.

- -

Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

- -

 

-

Example 1:

- -
Input: x = 123
-Output: 321
-
- -

Example 2:

- -
Input: x = -123
-Output: -321
-
- -

Example 3:

- -
Input: x = 120
-Output: 21
-
- -

 

-

Constraints:

- -
    -
  • -231 <= x <= 231 - 1
  • -
-
\ No newline at end of file diff --git a/0012-integer-to-roman/0012-integer-to-roman.cpp b/0012-integer-to-roman/0012-integer-to-roman.cpp deleted file mode 100644 index 9c86927..0000000 --- a/0012-integer-to-roman/0012-integer-to-roman.cpp +++ /dev/null @@ -1,15 +0,0 @@ -class Solution { -public: - string intToRoman(int num) { - int normal[]={1000,900,500,400,100,90,50,40,10,9,5,4,1}; - string roman[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; - string res; - for(int i=0;i<13;i++){ - while(num>=normal[i]){ - res.append(roman[i]); - num-=normal[i]; - } - } - return res; - } -}; \ No newline at end of file diff --git a/0012-integer-to-roman/README.md b/0012-integer-to-roman/README.md deleted file mode 100644 index 627b4bb..0000000 --- a/0012-integer-to-roman/README.md +++ /dev/null @@ -1,52 +0,0 @@ -

12. Integer to Roman

Medium


Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

- -
Symbol       Value
-I             1
-V             5
-X             10
-L             50
-C             100
-D             500
-M             1000
- -

For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

- -

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

- -
    -
  • I can be placed before V (5) and X (10) to make 4 and 9. 
  • -
  • X can be placed before L (50) and C (100) to make 40 and 90. 
  • -
  • C can be placed before D (500) and M (1000) to make 400 and 900.
  • -
- -

Given an integer, convert it to a roman numeral.

- -

 

-

Example 1:

- -
Input: num = 3
-Output: "III"
-Explanation: 3 is represented as 3 ones.
-
- -

Example 2:

- -
Input: num = 58
-Output: "LVIII"
-Explanation: L = 50, V = 5, III = 3.
-
- -

Example 3:

- -
Input: num = 1994
-Output: "MCMXCIV"
-Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
-
- -

 

-

Constraints:

- -
    -
  • 1 <= num <= 3999
  • -
-
\ No newline at end of file diff --git a/0013-roman-to-integer/0013-roman-to-integer.cpp b/0013-roman-to-integer/0013-roman-to-integer.cpp deleted file mode 100644 index db4b16f..0000000 --- a/0013-roman-to-integer/0013-roman-to-integer.cpp +++ /dev/null @@ -1,23 +0,0 @@ -class Solution { -public: -int romanToInt(string s) { - unordered_map mp{ - {'I',1}, - {'V',5}, - {'X',10}, - {'L',50}, - {'C',100}, - {'D',500}, - {'M',1000}, - }; - int ans =0; - for(int i=0;ist; - for(int i=0;i20. Valid Parentheses

Easy


Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

- -

An input string is valid if:

- -
    -
  1. Open brackets must be closed by the same type of brackets.
  2. -
  3. Open brackets must be closed in the correct order.
  4. -
  5. Every close bracket has a corresponding open bracket of the same type.
  6. -
- -

 

-

Example 1:

- -
Input: s = "()"
-Output: true
-
- -

Example 2:

- -
Input: s = "()[]{}"
-Output: true
-
- -

Example 3:

- -
Input: s = "(]"
-Output: false
-
- -

 

-

Constraints:

- -
    -
  • 1 <= s.length <= 104
  • -
  • s consists of parentheses only '()[]{}'.
  • -
-
\ No newline at end of file diff --git a/0034-find-first-and-last-position-of-element-in-sorted-array/0034-find-first-and-last-position-of-element-in-sorted-array.cpp b/0034-find-first-and-last-position-of-element-in-sorted-array/0034-find-first-and-last-position-of-element-in-sorted-array.cpp deleted file mode 100644 index bf4e2ef..0000000 --- a/0034-find-first-and-last-position-of-element-in-sorted-array/0034-find-first-and-last-position-of-element-in-sorted-array.cpp +++ /dev/null @@ -1,64 +0,0 @@ -class Solution { -public: - - int searchLeft(vector& nums,int low, int high, int target){ - - int fpos=-1; - - while(low<=high) - { - int mid=(low)+(high-low)/2; - if(nums[mid]==target) - { - fpos=mid; - high=mid-1; - } - else if(nums[mid]& nums,int low, int high, int target){ - - int lpos=-1; - - while(low<=high) - { - int mid=(low)+(high-low)/2; - - if(nums[mid]<=target) - { - if(nums[mid]==target) - lpos=mid; - low=mid+1; - } - else - { - high=mid-1; - } - } - return lpos; - - } - - vector searchRange(vector& nums, int target) { - - int low=0; - int high=nums.size()-1; - int fpos; - int lpos; - - fpos = searchLeft(nums,low,high,target); - lpos = searchRight(nums,low,high,target); - - return {fpos,lpos}; - } -}; \ No newline at end of file diff --git a/0034-find-first-and-last-position-of-element-in-sorted-array/README.md b/0034-find-first-and-last-position-of-element-in-sorted-array/README.md deleted file mode 100644 index 3ba57ee..0000000 --- a/0034-find-first-and-last-position-of-element-in-sorted-array/README.md +++ /dev/null @@ -1,27 +0,0 @@ -

34. Find First and Last Position of Element in Sorted Array

Medium


Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.

- -

If target is not found in the array, return [-1, -1].

- -

You must write an algorithm with O(log n) runtime complexity.

- -

 

-

Example 1:

-
Input: nums = [5,7,7,8,8,10], target = 8
-Output: [3,4]
-

Example 2:

-
Input: nums = [5,7,7,8,8,10], target = 6
-Output: [-1,-1]
-

Example 3:

-
Input: nums = [], target = 0
-Output: [-1,-1]
-
-

 

-

Constraints:

- -
    -
  • 0 <= nums.length <= 105
  • -
  • -109 <= nums[i] <= 109
  • -
  • nums is a non-decreasing array.
  • -
  • -109 <= target <= 109
  • -
-
\ No newline at end of file diff --git a/0035-search-insert-position/0035-search-insert-position.cpp b/0035-search-insert-position/0035-search-insert-position.cpp deleted file mode 100644 index 2285040..0000000 --- a/0035-search-insert-position/0035-search-insert-position.cpp +++ /dev/null @@ -1,27 +0,0 @@ -class Solution { -public: - int searchInsert(vector& nums, int target) { - - int l=0,h=nums.size()-1; - - int mid; - - while(l<=h){ - mid = (l+h)/2; - - if(nums[mid]==target) - return mid; - - else if(nums[mid]>target) - h = mid-1; - - else - l = mid+1; - } - return l; - } -}; - -// low 2 -//// low 3 -// low 4 \ No newline at end of file diff --git a/0035-search-insert-position/NOTES.md b/0035-search-insert-position/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0035-search-insert-position/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0055-jump-game/0055-jump-game.cpp b/0055-jump-game/0055-jump-game.cpp deleted file mode 100644 index a007435..0000000 --- a/0055-jump-game/0055-jump-game.cpp +++ /dev/null @@ -1,19 +0,0 @@ -class Solution { -public: - bool canJump(vector& nums) { - - int n = nums.size(); - int last = nums.size()-1; - int i; - - for(i=n-2;i>=0;i--){ - if(i+nums[i]>=last) - last = i; - } - - if(last==0) - return true; - - return false; - } -}; \ No newline at end of file diff --git a/0055-jump-game/README.md b/0055-jump-game/README.md deleted file mode 100644 index bfb8968..0000000 --- a/0055-jump-game/README.md +++ /dev/null @@ -1,27 +0,0 @@ -

55. Jump Game

Medium


You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.

- -

Return true if you can reach the last index, or false otherwise.

- -

 

-

Example 1:

- -
Input: nums = [2,3,1,1,4]
-Output: true
-Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.
-
- -

Example 2:

- -
Input: nums = [3,2,1,0,4]
-Output: false
-Explanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.
-
- -

 

-

Constraints:

- -
    -
  • 1 <= nums.length <= 104
  • -
  • 0 <= nums[i] <= 105
  • -
-
\ No newline at end of file diff --git a/0069-sqrtx/0069-sqrtx.cpp b/0069-sqrtx/0069-sqrtx.cpp deleted file mode 100644 index 016712c..0000000 --- a/0069-sqrtx/0069-sqrtx.cpp +++ /dev/null @@ -1,13 +0,0 @@ -class Solution { -public: - int mySqrt(int x) { - int i=0, j=x, ans; - while(i<=j){ - long long int mid=i+(j-i)/2; - if(mid*mid==x){ans = mid; break;} - else if(mid*mid69. Sqrt(x)

Easy


Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well.

- -

You must not use any built-in exponent function or operator.

- -
    -
  • For example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python.
  • -
- -

 

-

Example 1:

- -
Input: x = 4
-Output: 2
-Explanation: The square root of 4 is 2, so we return 2.
-
- -

Example 2:

- -
Input: x = 8
-Output: 2
-Explanation: The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned.
-
- -

 

-

Constraints:

- -
    -
  • 0 <= x <= 231 - 1
  • -
-
\ No newline at end of file diff --git a/0072-edit-distance/0072-edit-distance.cpp b/0072-edit-distance/0072-edit-distance.cpp deleted file mode 100644 index d06cdba..0000000 --- a/0072-edit-distance/0072-edit-distance.cpp +++ /dev/null @@ -1,28 +0,0 @@ -class Solution { -public: - int minDistance(string str1, string str2) { - - int n = str1.size(), m = str2.size(); - int i,j; - vector> dp(n+1, vector(m+1, 0)); - - for(i=0;i<=n;i++) - dp[i][0] = i; - - for(j=0;j<=m;j++) - dp[0][j] = j; - - for(i=1; i<=n; i++){ - for(j=1;j<=m;j++){ - - // string match - if(str1[i-1]==str2[j-1]) - dp[i][j] = dp[i-1][j-1]; - - else - dp[i][j] = 1 + min(dp[i-1][j], min(dp[i][j-1], dp[i-1][j-1])); - } - } - return dp[n][m]; - } -}; \ No newline at end of file diff --git a/0072-edit-distance/README.md b/0072-edit-distance/README.md deleted file mode 100644 index f63b24c..0000000 --- a/0072-edit-distance/README.md +++ /dev/null @@ -1,41 +0,0 @@ -

72. Edit Distance

Hard


Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.

- -

You have the following three operations permitted on a word:

- -
    -
  • Insert a character
  • -
  • Delete a character
  • -
  • Replace a character
  • -
- -

 

-

Example 1:

- -
Input: word1 = "horse", word2 = "ros"
-Output: 3
-Explanation: 
-horse -> rorse (replace 'h' with 'r')
-rorse -> rose (remove 'r')
-rose -> ros (remove 'e')
-
- -

Example 2:

- -
Input: word1 = "intention", word2 = "execution"
-Output: 5
-Explanation: 
-intention -> inention (remove 't')
-inention -> enention (replace 'i' with 'e')
-enention -> exention (replace 'n' with 'x')
-exention -> exection (replace 'n' with 'c')
-exection -> execution (insert 'u')
-
- -

 

-

Constraints:

- -
    -
  • 0 <= word1.length, word2.length <= 500
  • -
  • word1 and word2 consist of lowercase English letters.
  • -
-
\ No newline at end of file diff --git a/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.cpp b/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.cpp deleted file mode 100644 index b3061c2..0000000 --- a/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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 inorder(TreeNode* root, vector &v) { - - if (root != NULL) { - inorder(root->left,v); - v.push_back(root->val); - inorder(root->right,v); - } - } - - vector inorderTraversal(TreeNode* root) { - - vector v; - - inorder(root, v); - - return v; - } -}; \ No newline at end of file diff --git a/0094-binary-tree-inorder-traversal/NOTES.md b/0094-binary-tree-inorder-traversal/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0094-binary-tree-inorder-traversal/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0094-binary-tree-inorder-traversal/README.md b/0094-binary-tree-inorder-traversal/README.md deleted file mode 100644 index ad2de4d..0000000 --- a/0094-binary-tree-inorder-traversal/README.md +++ /dev/null @@ -1,31 +0,0 @@ -

94. Binary Tree Inorder Traversal

Easy


Given the root of a binary tree, return the inorder traversal of its nodes' values.

- -

 

-

Example 1:

- -
Input: root = [1,null,2,3]
-Output: [1,3,2]
-
- -

Example 2:

- -
Input: root = []
-Output: []
-
- -

Example 3:

- -
Input: root = [1]
-Output: [1]
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 100].
  • -
  • -100 <= Node.val <= 100
  • -
- -

 

-Follow up: Recursive solution is trivial, could you do it iteratively?
\ No newline at end of file diff --git a/0098-validate-binary-search-tree/0098-validate-binary-search-tree.cpp b/0098-validate-binary-search-tree/0098-validate-binary-search-tree.cpp deleted file mode 100644 index 4e36225..0000000 --- a/0098-validate-binary-search-tree/0098-validate-binary-search-tree.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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: - bool isValidBST(TreeNode* root) { - long long int maxValue = LONG_MAX; - long long int minValue = LONG_MIN; - return isBST(root, maxValue, minValue); - } - - bool isBST(TreeNode* root, long long int maxValue, long long int minValue){ - if(root==NULL) - return true; - - if(root->val >= maxValue || root->val <= minValue) - return false; - - bool left = isBST(root->left, root->val, minValue); - bool right = isBST(root->right, maxValue, root->val); - - return (left && right); - } -}; \ No newline at end of file diff --git a/0098-validate-binary-search-tree/README.md b/0098-validate-binary-search-tree/README.md deleted file mode 100644 index a5ec604..0000000 --- a/0098-validate-binary-search-tree/README.md +++ /dev/null @@ -1,32 +0,0 @@ -

98. Validate Binary Search Tree

Medium


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.
  • -
- -

 

-

Example 1:

- -
Input: root = [2,1,3]
-Output: true
-
- -

Example 2:

- -
Input: root = [5,1,4,null,null,3,6]
-Output: false
-Explanation: The root node's value is 5 but its right child's value is 4.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 104].
  • -
  • -231 <= Node.val <= 231 - 1
  • -
-
\ No newline at end of file diff --git a/0099-recover-binary-search-tree/0099-recover-binary-search-tree.cpp b/0099-recover-binary-search-tree/0099-recover-binary-search-tree.cpp deleted file mode 100644 index 535f810..0000000 --- a/0099-recover-binary-search-tree/0099-recover-binary-search-tree.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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: - - TreeNode* first; - TreeNode* last; - TreeNode* middle; - TreeNode* prev; - - void inorder(TreeNode*root){ - if(root==NULL) - return ; - - inorder(root->left); - - if(prev!=NULL && (prev->val > root->val)){ - if(first==NULL){ - first = prev; - middle = root; - } - - else - last = root; - } - - prev = root; - inorder(root->right); - } - - void recoverTree(TreeNode* root) { - first=last=middle= NULL; - prev = new TreeNode(INT_MIN); - inorder(root); - if(last && first) - swap(first->val, last->val); - - else if(middle && first) - swap(first->val, middle->val); - } -}; \ No newline at end of file diff --git a/0099-recover-binary-search-tree/NOTES.md b/0099-recover-binary-search-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0099-recover-binary-search-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0099-recover-binary-search-tree/README.md b/0099-recover-binary-search-tree/README.md deleted file mode 100644 index ce924b3..0000000 --- a/0099-recover-binary-search-tree/README.md +++ /dev/null @@ -1,27 +0,0 @@ -

99. Recover Binary Search Tree

Medium


You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure.

- -

 

-

Example 1:

- -
Input: root = [1,3,null,null,2]
-Output: [3,1,null,null,2]
-Explanation: 3 cannot be a left child of 1 because 3 > 1. Swapping 1 and 3 makes the BST valid.
-
- -

Example 2:

- -
Input: root = [3,1,4,null,null,2]
-Output: [2,1,4,null,null,3]
-Explanation: 2 cannot be in the right subtree of 3 because 2 < 3. Swapping 2 and 3 makes the BST valid.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [2, 1000].
  • -
  • -231 <= Node.val <= 231 - 1
  • -
- -

 

-Follow up: A solution using O(n) space is pretty straight-forward. Could you devise a constant O(1) space solution?
\ No newline at end of file diff --git a/0100-same-tree/0100-same-tree.cpp b/0100-same-tree/0100-same-tree.cpp deleted file mode 100644 index 366228a..0000000 --- a/0100-same-tree/0100-same-tree.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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: - bool isSameTree(TreeNode* p, TreeNode* q) { - if(p==NULL || q==NULL) - return p==q; - -// isSameTree(p->left, q->left); -// isSameTree(p->right, q->right); - - return isSameTree(p->left, q->left)&& isSameTree(p->right, q->right) &&(p->val == q->val); - - } -}; \ No newline at end of file diff --git a/0100-same-tree/NOTES.md b/0100-same-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0100-same-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0100-same-tree/README.md b/0100-same-tree/README.md deleted file mode 100644 index ac214aa..0000000 --- a/0100-same-tree/README.md +++ /dev/null @@ -1,31 +0,0 @@ -

100. Same Tree

Easy


Given the roots of two binary trees p and q, write a function to check if they are the same or not.

- -

Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

- -

 

-

Example 1:

- -
Input: p = [1,2,3], q = [1,2,3]
-Output: true
-
- -

Example 2:

- -
Input: p = [1,2], q = [1,null,2]
-Output: false
-
- -

Example 3:

- -
Input: p = [1,2,1], q = [1,1,2]
-Output: false
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in both trees is in the range [0, 100].
  • -
  • -104 <= Node.val <= 104
  • -
-
\ No newline at end of file diff --git a/0101-symmetric-tree/0101-symmetric-tree.cpp b/0101-symmetric-tree/0101-symmetric-tree.cpp deleted file mode 100644 index 3d857cb..0000000 --- a/0101-symmetric-tree/0101-symmetric-tree.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/** - * 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: - - bool check(TreeNode* p, TreeNode* q){ - - if(p==NULL || q==NULL) - return p==q; - - return check(p->left, q->right) && check(p->right, q->left) && (p->val == q->val); - } - - bool isSymmetric(TreeNode* root) { - - return check(root, root); - } -}; \ No newline at end of file diff --git a/0101-symmetric-tree/NOTES.md b/0101-symmetric-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0101-symmetric-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0101-symmetric-tree/README.md b/0101-symmetric-tree/README.md deleted file mode 100644 index a4b74c2..0000000 --- a/0101-symmetric-tree/README.md +++ /dev/null @@ -1,25 +0,0 @@ -

101. Symmetric Tree

Easy


Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

- -

 

-

Example 1:

- -
Input: root = [1,2,2,3,4,4,3]
-Output: true
-
- -

Example 2:

- -
Input: root = [1,2,2,null,3,null,3]
-Output: false
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 1000].
  • -
  • -100 <= Node.val <= 100
  • -
- -

 

-Follow up: Could you solve it both recursively and iteratively?
\ No newline at end of file diff --git a/0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.cpp b/0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.cpp deleted file mode 100644 index 5f312ff..0000000 --- a/0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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: - vector> levelOrder(TreeNode* root) { - vector> res; - - if(root==NULL) - return res; - - queue nodesQueue; - nodesQueue.push(root); - - while(!nodesQueue.empty()){ - int size = nodesQueue.size(); - vector row(size); - - for(int i = 0;ival); - - if(node->left) - nodesQueue.push(node->left); - - if(node->right) - nodesQueue.push(node->right); - - } - res.push_back(row); - } - - return res; - } -}; \ No newline at end of file diff --git a/0102-binary-tree-level-order-traversal/NOTES.md b/0102-binary-tree-level-order-traversal/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0102-binary-tree-level-order-traversal/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0102-binary-tree-level-order-traversal/README.md b/0102-binary-tree-level-order-traversal/README.md deleted file mode 100644 index dc78860..0000000 --- a/0102-binary-tree-level-order-traversal/README.md +++ /dev/null @@ -1,29 +0,0 @@ -

102. Binary Tree Level Order Traversal

Medium


Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

- -

 

-

Example 1:

- -
Input: root = [3,9,20,null,null,15,7]
-Output: [[3],[9,20],[15,7]]
-
- -

Example 2:

- -
Input: root = [1]
-Output: [[1]]
-
- -

Example 3:

- -
Input: root = []
-Output: []
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 2000].
  • -
  • -1000 <= Node.val <= 1000
  • -
-
\ No newline at end of file diff --git a/0103-binary-tree-zigzag-level-order-traversal/0103-binary-tree-zigzag-level-order-traversal.cpp b/0103-binary-tree-zigzag-level-order-traversal/0103-binary-tree-zigzag-level-order-traversal.cpp deleted file mode 100644 index dc5fca1..0000000 --- a/0103-binary-tree-zigzag-level-order-traversal/0103-binary-tree-zigzag-level-order-traversal.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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: - vector> zigzagLevelOrder(TreeNode* root) { - - vector> res; - - if(root==NULL) - return res; - - queue nodesQueue; - nodesQueue.push(root); - bool leftToRight = true; - - while(!nodesQueue.empty()){ - int size = nodesQueue.size(); - vector row(size); - - for(int i=0;ival; - - if(node->left) - nodesQueue.push(node->left); - - if(node->right) - nodesQueue.push(node->right); - } - leftToRight = !leftToRight; - res.push_back(row); - } - - return res; - } -}; \ No newline at end of file diff --git a/0103-binary-tree-zigzag-level-order-traversal/NOTES.md b/0103-binary-tree-zigzag-level-order-traversal/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0103-binary-tree-zigzag-level-order-traversal/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0103-binary-tree-zigzag-level-order-traversal/README.md b/0103-binary-tree-zigzag-level-order-traversal/README.md deleted file mode 100644 index 001e9e3..0000000 --- a/0103-binary-tree-zigzag-level-order-traversal/README.md +++ /dev/null @@ -1,29 +0,0 @@ -

103. Binary Tree Zigzag Level Order Traversal

Medium


Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).

- -

 

-

Example 1:

- -
Input: root = [3,9,20,null,null,15,7]
-Output: [[3],[20,9],[15,7]]
-
- -

Example 2:

- -
Input: root = [1]
-Output: [[1]]
-
- -

Example 3:

- -
Input: root = []
-Output: []
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 2000].
  • -
  • -100 <= Node.val <= 100
  • -
-
\ No newline at end of file diff --git a/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.cpp b/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.cpp deleted file mode 100644 index 8fa0f51..0000000 --- a/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/** - * 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: - int maxDepth(TreeNode* root) { - - if(root == NULL) - return 0; - - int l = maxDepth(root->left); - int r = maxDepth(root->right); - - int result = 1 + max(l,r); - - return result; - } -}; \ No newline at end of file diff --git a/0104-maximum-depth-of-binary-tree/NOTES.md b/0104-maximum-depth-of-binary-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0104-maximum-depth-of-binary-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0104-maximum-depth-of-binary-tree/README.md b/0104-maximum-depth-of-binary-tree/README.md deleted file mode 100644 index e5aefdf..0000000 --- a/0104-maximum-depth-of-binary-tree/README.md +++ /dev/null @@ -1,25 +0,0 @@ -

104. Maximum Depth of Binary Tree

Easy


Given the root of a binary tree, return its maximum depth.

- -

A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

- -

 

-

Example 1:

- -
Input: root = [3,9,20,null,null,15,7]
-Output: 3
-
- -

Example 2:

- -
Input: root = [1,null,2]
-Output: 2
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 104].
  • -
  • -100 <= Node.val <= 100
  • -
-
\ No newline at end of file diff --git a/0105-construct-binary-tree-from-preorder-and-inorder-traversal/0105-construct-binary-tree-from-preorder-and-inorder-traversal.cpp b/0105-construct-binary-tree-from-preorder-and-inorder-traversal/0105-construct-binary-tree-from-preorder-and-inorder-traversal.cpp deleted file mode 100644 index 1f89768..0000000 --- a/0105-construct-binary-tree-from-preorder-and-inorder-traversal/0105-construct-binary-tree-from-preorder-and-inorder-traversal.cpp +++ /dev/null @@ -1,30 +0,0 @@ -class Solution { -public: - TreeNode* buildTree(vector& preorder, vector& inorder) { - unordered_mapmp; - for(int i =0;i& preorder,int prstart,int prend,vector& inorder,int instart,int - inend,unordered_map&mp){ - - //Base case - if(prstart>prend || instart>inend) return NULL; - TreeNode* root = new TreeNode(preorder[prstart]); - - //Pointers to Subsequent ROOT and Number of left numbers to root - int inRoot = mp[root->val]; - int numsLeft = inRoot - instart; - - root->left = func(preorder,prstart+1,prstart+numsLeft,inorder,instart,inRoot-1,mp); - root->right = func(preorder,prstart+numsLeft+1,prend,inorder,inRoot+1,inend,mp); - - return root; - - } - - -}; \ No newline at end of file diff --git a/0105-construct-binary-tree-from-preorder-and-inorder-traversal/README.md b/0105-construct-binary-tree-from-preorder-and-inorder-traversal/README.md deleted file mode 100644 index ad7d1dc..0000000 --- a/0105-construct-binary-tree-from-preorder-and-inorder-traversal/README.md +++ /dev/null @@ -1,28 +0,0 @@ -

105. Construct Binary Tree from Preorder and Inorder Traversal

Medium


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

- -

 

-

Example 1:

- -
Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
-Output: [3,9,20,null,null,15,7]
-
- -

Example 2:

- -
Input: preorder = [-1], inorder = [-1]
-Output: [-1]
-
- -

 

-

Constraints:

- -
    -
  • 1 <= preorder.length <= 3000
  • -
  • inorder.length == preorder.length
  • -
  • -3000 <= preorder[i], inorder[i] <= 3000
  • -
  • preorder and inorder consist of unique values.
  • -
  • Each value of inorder also appears in preorder.
  • -
  • preorder is guaranteed to be the preorder traversal of the tree.
  • -
  • inorder is guaranteed to be the inorder traversal of the tree.
  • -
-
\ No newline at end of file diff --git a/0106-construct-binary-tree-from-inorder-and-postorder-traversal/0106-construct-binary-tree-from-inorder-and-postorder-traversal.cpp b/0106-construct-binary-tree-from-inorder-and-postorder-traversal/0106-construct-binary-tree-from-inorder-and-postorder-traversal.cpp deleted file mode 100644 index 9ff178e..0000000 --- a/0106-construct-binary-tree-from-inorder-and-postorder-traversal/0106-construct-binary-tree-from-inorder-and-postorder-traversal.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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: - TreeNode* func(vector&inorder, int is, int ie, - vector&postorder, int ps, int pe, - unordered_map&inMap ){ - - if(ps > pe || is> ie) - return NULL; - - TreeNode* root = new TreeNode(postorder[pe]); - - int inRoot = inMap[root->val]; - int numsLeft = inRoot - is; - - root->left = func(inorder,is , inRoot-1, - postorder, ps, ps+numsLeft-1, inMap); - - root->right = func(inorder,inRoot+1,ie, - postorder, ps+numsLeft, pe-1, inMap); - - return root; - } - - TreeNode* buildTree(vector& inorder, vector& postorder) { - unordered_mapinMap; - - for(int i = 0 ; i106. Construct Binary Tree from Inorder and Postorder Traversal

Medium


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

- -

 

-

Example 1:

- -
Input: inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]
-Output: [3,9,20,null,null,15,7]
-
- -

Example 2:

- -
Input: inorder = [-1], postorder = [-1]
-Output: [-1]
-
- -

 

-

Constraints:

- -
    -
  • 1 <= inorder.length <= 3000
  • -
  • postorder.length == inorder.length
  • -
  • -3000 <= inorder[i], postorder[i] <= 3000
  • -
  • inorder and postorder consist of unique values.
  • -
  • Each value of postorder also appears in inorder.
  • -
  • inorder is guaranteed to be the inorder traversal of the tree.
  • -
  • postorder is guaranteed to be the postorder traversal of the tree.
  • -
-
\ No newline at end of file diff --git a/0107-binary-tree-level-order-traversal-ii/0107-binary-tree-level-order-traversal-ii.cpp b/0107-binary-tree-level-order-traversal-ii/0107-binary-tree-level-order-traversal-ii.cpp deleted file mode 100644 index 47cadb9..0000000 --- a/0107-binary-tree-level-order-traversal-ii/0107-binary-tree-level-order-traversal-ii.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/** - * 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: - vector> levelOrderBottom(TreeNode* root) { - vector> res; - - if(root==NULL) - return res; - - queue nodesQueue; - nodesQueue.push(root); - - while(!nodesQueue.empty()){ - int size = nodesQueue.size(); - vector row(size); - - for(int i = 0;ival); - - if(node->left) - nodesQueue.push(node->left); - - if(node->right) - nodesQueue.push(node->right); - - } - res.push_back(row); - } - - int nn = res.size(); - vector> ans; - - - for(int i=nn-1;i>=0;i--){ - vector tree; - for(int j = 0;j107. Binary Tree Level Order Traversal II

Medium


Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).

- -

 

-

Example 1:

- -
Input: root = [3,9,20,null,null,15,7]
-Output: [[15,7],[9,20],[3]]
-
- -

Example 2:

- -
Input: root = [1]
-Output: [[1]]
-
- -

Example 3:

- -
Input: root = []
-Output: []
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 2000].
  • -
  • -1000 <= Node.val <= 1000
  • -
-
\ No newline at end of file diff --git a/0110-balanced-binary-tree/0110-balanced-binary-tree.cpp b/0110-balanced-binary-tree/0110-balanced-binary-tree.cpp deleted file mode 100644 index cc68cce..0000000 --- a/0110-balanced-binary-tree/0110-balanced-binary-tree.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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: - - int isDfs(TreeNode* root){ - if(root==NULL) - return 0; - - int lh = isDfs(root->left); - if(lh==-1) return -1; - - int rh = isDfs(root->right); - if(rh==-1) return -1; - - if(abs(lh-rh)>1) - return -1; - - return max(lh,rh)+1; - - } - - bool isBalanced(TreeNode* root) { - return isDfs(root) != -1 ; - } -}; \ No newline at end of file diff --git a/0110-balanced-binary-tree/NOTES.md b/0110-balanced-binary-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0110-balanced-binary-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0110-balanced-binary-tree/README.md b/0110-balanced-binary-tree/README.md deleted file mode 100644 index 2538e93..0000000 --- a/0110-balanced-binary-tree/README.md +++ /dev/null @@ -1,35 +0,0 @@ -

110. Balanced Binary Tree

Easy


Given a binary tree, determine if it is height-balanced.

- -

For this problem, a height-balanced binary tree is defined as:

- -
-

a binary tree in which the left and right subtrees of every node differ in height by no more than 1.

-
- -

 

-

Example 1:

- -
Input: root = [3,9,20,null,null,15,7]
-Output: true
-
- -

Example 2:

- -
Input: root = [1,2,2,3,3,null,null,4,4]
-Output: false
-
- -

Example 3:

- -
Input: root = []
-Output: true
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 5000].
  • -
  • -104 <= Node.val <= 104
  • -
-
\ No newline at end of file diff --git a/0115-distinct-subsequences/0115-distinct-subsequences.cpp b/0115-distinct-subsequences/0115-distinct-subsequences.cpp deleted file mode 100644 index 6e61dba..0000000 --- a/0115-distinct-subsequences/0115-distinct-subsequences.cpp +++ /dev/null @@ -1,39 +0,0 @@ -class Solution { -public: - int numDistinct(string text1, string text2) { - - int n = text1.size() , m = text2.size(); - int i,j; - int ans = 0; - - vector> dp(n+1, vector(m+1,0)); - - for(i=0;i<=n;i++) - dp[i][0] = 1; - - for(j=1;j<=m;j++) - dp[0][j] = 0; - - for(i=1;i<=n;i++){ - for(j=1;j<=m;j++){ - - if(text1[i-1] == text2[j-1]){ - dp[i][j] = dp[i-1][j-1] + dp[i-1][j]; - // ans = max(ans,dp[i][j]); - } - - else - dp[i][j] = dp[i-1][j]; - } - } - - // for(i=0; i<=n; i++){ - // for(j=0; j<=m; j++){ - // cout << dp[i][j] << " "; - // } - // cout << endl; - // } - - return (int)dp[n][m]; - } -}; \ No newline at end of file diff --git a/0115-distinct-subsequences/README.md b/0115-distinct-subsequences/README.md deleted file mode 100644 index 224385d..0000000 --- a/0115-distinct-subsequences/README.md +++ /dev/null @@ -1,38 +0,0 @@ -

115. Distinct Subsequences

Hard


Given two strings s and t, return the number of distinct subsequences of s which equals t.

- -

A string's subsequence is a new string formed from the original string by deleting some (can be none) of the characters without disturbing the remaining characters' relative positions. (i.e., "ACE" is a subsequence of "ABCDE" while "AEC" is not).

- -

The test cases are generated so that the answer fits on a 32-bit signed integer.

- -

 

-

Example 1:

- -
Input: s = "rabbbit", t = "rabbit"
-Output: 3
-Explanation:
-As shown below, there are 3 ways you can generate "rabbit" from s.
-rabbbit
-rabbbit
-rabbbit
-
- -

Example 2:

- -
Input: s = "babgbag", t = "bag"
-Output: 5
-Explanation:
-As shown below, there are 5 ways you can generate "bag" from s.
-babgbag
-babgbag
-babgbag
-babgbag
-babgbag
- -

 

-

Constraints:

- -
    -
  • 1 <= s.length, t.length <= 1000
  • -
  • s and t consist of English letters.
  • -
-
\ No newline at end of file diff --git a/0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.cpp b/0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.cpp deleted file mode 100644 index a4cf9d7..0000000 --- a/0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.cpp +++ /dev/null @@ -1,33 +0,0 @@ -class Solution { -public: - int maxProfit(vector& prices) { - - int n = prices.size(); - vector> dp(n+1, vector(2,0)); - - dp[n][0] = dp[n][1] = 0; - - for(int ind = n-1; ind>=0; ind--){ - for(int buy = 0; buy<=1; buy++){ - long profit = 0; - - if(buy){ - profit = max(-prices[ind]+dp[ind+1][0], 0+dp[ind+1][1]); - } - - else{ - profit = max(prices[ind]+dp[ind+1][1] , dp[ind+1][0]); - } - dp[ind][buy] = profit; - } - } - - // for(int i=0;i<=n;i++){ - // for(int buy = 0; buy<=1; buy++){ - // cout << dp[i][buy] << " "; - // } - // cout << endl; - // } - return dp[0][1]; - } -}; \ No newline at end of file diff --git a/0122-best-time-to-buy-and-sell-stock-ii/NOTES.md b/0122-best-time-to-buy-and-sell-stock-ii/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0122-best-time-to-buy-and-sell-stock-ii/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0122-best-time-to-buy-and-sell-stock-ii/README.md b/0122-best-time-to-buy-and-sell-stock-ii/README.md deleted file mode 100644 index 0cf1818..0000000 --- a/0122-best-time-to-buy-and-sell-stock-ii/README.md +++ /dev/null @@ -1,39 +0,0 @@ -

122. Best Time to Buy and Sell Stock II

Medium


You are given an integer array prices where prices[i] is the price of a given stock on the ith day.

- -

On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day.

- -

Find and return the maximum profit you can achieve.

- -

 

-

Example 1:

- -
Input: prices = [7,1,5,3,6,4]
-Output: 7
-Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
-Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
-Total profit is 4 + 3 = 7.
-
- -

Example 2:

- -
Input: prices = [1,2,3,4,5]
-Output: 4
-Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
-Total profit is 4.
-
- -

Example 3:

- -
Input: prices = [7,6,4,3,1]
-Output: 0
-Explanation: There is no way to make a positive profit, so we never buy the stock to achieve the maximum profit of 0.
-
- -

 

-

Constraints:

- -
    -
  • 1 <= prices.length <= 3 * 104
  • -
  • 0 <= prices[i] <= 104
  • -
-
\ No newline at end of file diff --git a/0124-binary-tree-maximum-path-sum/0124-binary-tree-maximum-path-sum.cpp b/0124-binary-tree-maximum-path-sum/0124-binary-tree-maximum-path-sum.cpp deleted file mode 100644 index 95a16bb..0000000 --- a/0124-binary-tree-maximum-path-sum/0124-binary-tree-maximum-path-sum.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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: - - int path(TreeNode* root, int &maxi){ - - if(root==NULL) - return 0; - - int lh = max(0,path(root->left, maxi)); - int rh = max(0,path(root->right, maxi)); - - maxi = max(maxi,lh+rh+root->val); - - return root->val + max(lh,rh); - } - - int maxPathSum(TreeNode* root) { - - int maxi = INT_MIN; - path(root,maxi); - - return maxi; - - } -}; \ No newline at end of file diff --git a/0124-binary-tree-maximum-path-sum/NOTES.md b/0124-binary-tree-maximum-path-sum/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0124-binary-tree-maximum-path-sum/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0124-binary-tree-maximum-path-sum/README.md b/0124-binary-tree-maximum-path-sum/README.md deleted file mode 100644 index 768e3d6..0000000 --- a/0124-binary-tree-maximum-path-sum/README.md +++ /dev/null @@ -1,29 +0,0 @@ -

124. Binary Tree Maximum Path Sum

Hard


A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root.

- -

The path sum of a path is the sum of the node's values in the path.

- -

Given the root of a binary tree, return the maximum path sum of any non-empty path.

- -

 

-

Example 1:

- -
Input: root = [1,2,3]
-Output: 6
-Explanation: The optimal path is 2 -> 1 -> 3 with a path sum of 2 + 1 + 3 = 6.
-
- -

Example 2:

- -
Input: root = [-10,9,20,null,null,15,7]
-Output: 42
-Explanation: The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 = 42.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 3 * 104].
  • -
  • -1000 <= Node.val <= 1000
  • -
-
\ No newline at end of file diff --git a/0128-longest-consecutive-sequence/0128-longest-consecutive-sequence.cpp b/0128-longest-consecutive-sequence/0128-longest-consecutive-sequence.cpp deleted file mode 100644 index 8807dc1..0000000 --- a/0128-longest-consecutive-sequence/0128-longest-consecutive-sequence.cpp +++ /dev/null @@ -1,23 +0,0 @@ -class Solution { -public: - int longestConsecutive(vector& arr) { - int n = arr.size(); - unordered_set st; - int res = 0; - for(int i=0;i v; - - void preorder(TreeNode* root){ - - if(root==NULL) - return ; - - v.push_back(root->val); - preorder(root->left); - preorder(root->right); - } - - vector preorderTraversal(TreeNode* root) { - - preorder(root); - return v; - } -}; \ No newline at end of file diff --git a/0144-binary-tree-preorder-traversal/NOTES.md b/0144-binary-tree-preorder-traversal/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0144-binary-tree-preorder-traversal/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.cpp b/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.cpp deleted file mode 100644 index b5025a7..0000000 --- a/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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: - - vector v; - - void postorder(TreeNode * root){ - if(root==NULL) - return; - - postorder(root->left); - postorder(root->right); - - v.push_back(root->val); - } - - vector postorderTraversal(TreeNode* root) { - - postorder(root); - return v; - } -}; \ No newline at end of file diff --git a/0145-binary-tree-postorder-traversal/README.md b/0145-binary-tree-postorder-traversal/README.md deleted file mode 100644 index ed52ab8..0000000 --- a/0145-binary-tree-postorder-traversal/README.md +++ /dev/null @@ -1,31 +0,0 @@ -

145. Binary Tree Postorder Traversal

Easy


Given the root of a binary tree, return the postorder traversal of its nodes' values.

- -

 

-

Example 1:

- -
Input: root = [1,null,2,3]
-Output: [3,2,1]
-
- -

Example 2:

- -
Input: root = []
-Output: []
-
- -

Example 3:

- -
Input: root = [1]
-Output: [1]
-
- -

 

-

Constraints:

- -
    -
  • The number of the nodes in the tree is in the range [0, 100].
  • -
  • -100 <= Node.val <= 100
  • -
- -

 

-Follow up: Recursive solution is trivial, could you do it iteratively?
\ No newline at end of file diff --git a/0162-find-peak-element/0162-find-peak-element.cpp b/0162-find-peak-element/0162-find-peak-element.cpp deleted file mode 100644 index 46e2f7d..0000000 --- a/0162-find-peak-element/0162-find-peak-element.cpp +++ /dev/null @@ -1,29 +0,0 @@ -class Solution { -public: - int findPeakElement(vector& nums) { - - int l = 0; - int h= nums.size()-1; - int n= nums.size(); - - if(n==1) - return 0; - - while(l<=h){ - int mid = (l+h)/2; - - if((mid == 0 || nums[mid]>nums[mid-1]) && (mid ==n-1 || nums[mid]>nums[mid+1])){ - return mid; - break; - } - - else if(nums[mid] > nums[mid+1]){ - h = mid-1; - } - - else l= mid+1; - } - - return 0; - } -}; \ No newline at end of file diff --git a/0162-find-peak-element/NOTES.md b/0162-find-peak-element/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0162-find-peak-element/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0162-find-peak-element/README.md b/0162-find-peak-element/README.md deleted file mode 100644 index 96c32bd..0000000 --- a/0162-find-peak-element/README.md +++ /dev/null @@ -1,30 +0,0 @@ -

162. Find Peak Element

Medium


A peak element is an element that is strictly greater than its neighbors.

- -

Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.

- -

You may imagine that nums[-1] = nums[n] = -∞. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array.

- -

You must write an algorithm that runs in O(log n) time.

- -

 

-

Example 1:

- -
Input: nums = [1,2,3,1]
-Output: 2
-Explanation: 3 is a peak element and your function should return the index number 2.
- -

Example 2:

- -
Input: nums = [1,2,1,3,5,6,4]
-Output: 5
-Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
- -

 

-

Constraints:

- -
    -
  • 1 <= nums.length <= 1000
  • -
  • -231 <= nums[i] <= 231 - 1
  • -
  • nums[i] != nums[i + 1] for all valid i.
  • -
-
\ No newline at end of file diff --git a/0173-binary-search-tree-iterator/0173-binary-search-tree-iterator.cpp b/0173-binary-search-tree-iterator/0173-binary-search-tree-iterator.cpp deleted file mode 100644 index 4966570..0000000 --- a/0173-binary-search-tree-iterator/0173-binary-search-tree-iterator.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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 BSTIterator { -public: - - stackmyStack; - - BSTIterator(TreeNode* root) { - pushAll(root); - } - - int next() { - TreeNode * top = myStack.top(); - myStack.pop(); - pushAll(top->right); - return top->val; - } - - bool hasNext() { - return !myStack.empty(); - } - - void pushAll(TreeNode*node){ - - while(node!=NULL){ - myStack.push(node); - node = node->left; - } - } -}; - -/** - * Your BSTIterator object will be instantiated and called as such: - * BSTIterator* obj = new BSTIterator(root); - * int param_1 = obj->next(); - * bool param_2 = obj->hasNext(); - */ \ No newline at end of file diff --git a/0173-binary-search-tree-iterator/NOTES.md b/0173-binary-search-tree-iterator/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0173-binary-search-tree-iterator/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0173-binary-search-tree-iterator/README.md b/0173-binary-search-tree-iterator/README.md deleted file mode 100644 index 757bd0c..0000000 --- a/0173-binary-search-tree-iterator/README.md +++ /dev/null @@ -1,50 +0,0 @@ -

173. Binary Search Tree Iterator

Medium


Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):

- -
    -
  • BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST.
  • -
  • boolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise returns false.
  • -
  • int next() Moves the pointer to the right, then returns the number at the pointer.
  • -
- -

Notice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the smallest element in the BST.

- -

You may assume that next() calls will always be valid. That is, there will be at least a next number in the in-order traversal when next() is called.

- -

 

-

Example 1:

- -
Input
-["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"]
-[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]
-Output
-[null, 3, 7, true, 9, true, 15, true, 20, false]
-
-Explanation
-BSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);
-bSTIterator.next();    // return 3
-bSTIterator.next();    // return 7
-bSTIterator.hasNext(); // return True
-bSTIterator.next();    // return 9
-bSTIterator.hasNext(); // return True
-bSTIterator.next();    // return 15
-bSTIterator.hasNext(); // return True
-bSTIterator.next();    // return 20
-bSTIterator.hasNext(); // return False
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 105].
  • -
  • 0 <= Node.val <= 106
  • -
  • At most 105 calls will be made to hasNext, and next.
  • -
- -

 

-

Follow up:

- -
    -
  • Could you implement next() and hasNext() to run in average O(1) time and use O(h) memory, where h is the height of the tree?
  • -
-
\ No newline at end of file diff --git a/0199-binary-tree-right-side-view/0199-binary-tree-right-side-view.cpp b/0199-binary-tree-right-side-view/0199-binary-tree-right-side-view.cpp deleted file mode 100644 index c2c1b9d..0000000 --- a/0199-binary-tree-right-side-view/0199-binary-tree-right-side-view.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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: - vector rightSideView(TreeNode* root) { - vector res; - - if(root==NULL) - return res; - int ans; - queue nodesQueue; - nodesQueue.push(root); - - while(!nodesQueue.empty()){ - int size = nodesQueue.size(); - vector row(size); - - for(int i = 0;ival); - - if(node->left) - nodesQueue.push(node->left); - - if(node->right) - nodesQueue.push(node->right); - - } - res.push_back(row[size-1]); - // ans = row[0]; - } - // int n = res.size()-1; - // return res[n][0]; - return res; - } -}; \ No newline at end of file diff --git a/0199-binary-tree-right-side-view/NOTES.md b/0199-binary-tree-right-side-view/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0199-binary-tree-right-side-view/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0199-binary-tree-right-side-view/README.md b/0199-binary-tree-right-side-view/README.md deleted file mode 100644 index f51b0d5..0000000 --- a/0199-binary-tree-right-side-view/README.md +++ /dev/null @@ -1,29 +0,0 @@ -

199. Binary Tree Right Side View

Medium


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

- -

 

-

Example 1:

- -
Input: root = [1,2,3,null,5,null,4]
-Output: [1,3,4]
-
- -

Example 2:

- -
Input: root = [1,null,3]
-Output: [1,3]
-
- -

Example 3:

- -
Input: root = []
-Output: []
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 100].
  • -
  • -100 <= Node.val <= 100
  • -
-
\ No newline at end of file diff --git a/0222-count-complete-tree-nodes/0222-count-complete-tree-nodes.cpp b/0222-count-complete-tree-nodes/0222-count-complete-tree-nodes.cpp deleted file mode 100644 index 3e6839c..0000000 --- a/0222-count-complete-tree-nodes/0222-count-complete-tree-nodes.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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: - - int countNodes(TreeNode* root) { - // vector> res; - - if(root==NULL) - return 0; - - int ans = 0; - queue nodesQueue; - nodesQueue.push(root); - - while(!nodesQueue.empty()){ - int size = nodesQueue.size(); - vector row(size); - ans += size; - for(int i = 0;ival); - - if(node->left) - nodesQueue.push(node->left); - - if(node->right) - nodesQueue.push(node->right); - - } - // res.push_back(row); - } - - return ans; - } -}; \ No newline at end of file diff --git a/0222-count-complete-tree-nodes/NOTES.md b/0222-count-complete-tree-nodes/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0222-count-complete-tree-nodes/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0222-count-complete-tree-nodes/README.md b/0222-count-complete-tree-nodes/README.md deleted file mode 100644 index e961402..0000000 --- a/0222-count-complete-tree-nodes/README.md +++ /dev/null @@ -1,34 +0,0 @@ -

222. Count Complete Tree Nodes

Medium


Given the root of a complete binary tree, return the number of the nodes in the tree.

- -

According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

- -

Design an algorithm that runs in less than O(n) time complexity.

- -

 

-

Example 1:

- -
Input: root = [1,2,3,4,5,6]
-Output: 6
-
- -

Example 2:

- -
Input: root = []
-Output: 0
-
- -

Example 3:

- -
Input: root = [1]
-Output: 1
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 5 * 104].
  • -
  • 0 <= Node.val <= 5 * 104
  • -
  • The tree is guaranteed to be complete.
  • -
-
\ No newline at end of file diff --git a/0226-invert-binary-tree/0226-invert-binary-tree.cpp b/0226-invert-binary-tree/0226-invert-binary-tree.cpp deleted file mode 100644 index 7e3b6a0..0000000 --- a/0226-invert-binary-tree/0226-invert-binary-tree.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 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* p, TreeNode* q){ - -// TreeNode* node = p; -// p = q; -// q = node; - -// invert(p->left, q->right); -// invert(p->right, q->left); - -// } - - TreeNode* invertTree(TreeNode* root) { - - if(root==NULL) - return root; - - invertTree(root->left); - invertTree(root->right); - - TreeNode* curr = root->right; - root->right = root->left; - root->left = curr; - - - return root; - } -}; \ No newline at end of file diff --git a/0226-invert-binary-tree/README.md b/0226-invert-binary-tree/README.md deleted file mode 100644 index 253f28a..0000000 --- a/0226-invert-binary-tree/README.md +++ /dev/null @@ -1,29 +0,0 @@ -

226. Invert Binary Tree

Easy


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

- -

 

-

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]
-
- -

Example 3:

- -
Input: root = []
-Output: []
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 100].
  • -
  • -100 <= Node.val <= 100
  • -
-
\ No newline at end of file diff --git a/0230-kth-smallest-element-in-a-bst/0230-kth-smallest-element-in-a-bst.cpp b/0230-kth-smallest-element-in-a-bst/0230-kth-smallest-element-in-a-bst.cpp deleted file mode 100644 index eb539b2..0000000 --- a/0230-kth-smallest-element-in-a-bst/0230-kth-smallest-element-in-a-bst.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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 find(TreeNode* root, int k , int&c, int&ans){ - - if(root!=NULL){ - - find(root->left,k,c,ans); - - // cout << root->val; - c++; - // cout << c; - if(c==k){ - // cout << c; - // cout << root->val; - ans = root->val; - } - - - - - - find(root->right,k,c,ans); - } - } - // return -1; - - - int kthSmallest(TreeNode* root, int k) { - int c = 0; int ans; - find(root,k,c,ans); - return ans; - } -}; \ No newline at end of file diff --git a/0230-kth-smallest-element-in-a-bst/README.md b/0230-kth-smallest-element-in-a-bst/README.md deleted file mode 100644 index ab77328..0000000 --- a/0230-kth-smallest-element-in-a-bst/README.md +++ /dev/null @@ -1,27 +0,0 @@ -

230. Kth Smallest Element in a BST

Medium


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.

- -

 

-

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 <= 104
  • -
  • 0 <= Node.val <= 104
  • -
- -

 

-

Follow up: If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize?

-
\ No newline at end of file diff --git a/0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.cpp b/0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.cpp deleted file mode 100644 index 8750555..0000000 --- a/0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { - - if(root==NULL || root == p || root ==q) - return root; - - TreeNode * left = lowestCommonAncestor(root->left,p,q); - TreeNode * right = lowestCommonAncestor(root->right,p,q); - - if(left==NULL) - return right; - - else if(right==NULL) - return left; - - else - return root; - } -}; \ No newline at end of file diff --git a/0235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md b/0235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0236-lowest-common-ancestor-of-a-binary-tree/0236-lowest-common-ancestor-of-a-binary-tree.cpp b/0236-lowest-common-ancestor-of-a-binary-tree/0236-lowest-common-ancestor-of-a-binary-tree.cpp deleted file mode 100644 index 8750555..0000000 --- a/0236-lowest-common-ancestor-of-a-binary-tree/0236-lowest-common-ancestor-of-a-binary-tree.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { - - if(root==NULL || root == p || root ==q) - return root; - - TreeNode * left = lowestCommonAncestor(root->left,p,q); - TreeNode * right = lowestCommonAncestor(root->right,p,q); - - if(left==NULL) - return right; - - else if(right==NULL) - return left; - - else - return root; - } -}; \ No newline at end of file diff --git a/0236-lowest-common-ancestor-of-a-binary-tree/NOTES.md b/0236-lowest-common-ancestor-of-a-binary-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0236-lowest-common-ancestor-of-a-binary-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0278-first-bad-version/0278-first-bad-version.cpp b/0278-first-bad-version/0278-first-bad-version.cpp deleted file mode 100644 index acae2c6..0000000 --- a/0278-first-bad-version/0278-first-bad-version.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// The API isBadVersion is defined for you. -// bool isBadVersion(int version); - -class Solution { -public: - int firstBadVersion(int n) { - int l = 1,h = n; - while(l <= h){ - int mid = l + (h-l)/2; - if(isBadVersion(mid) == false) l = mid+1; - else h = mid-1; - } - return l; - } -}; \ No newline at end of file diff --git a/0278-first-bad-version/NOTES.md b/0278-first-bad-version/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0278-first-bad-version/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0278-first-bad-version/README.md b/0278-first-bad-version/README.md deleted file mode 100644 index ee43afc..0000000 --- a/0278-first-bad-version/README.md +++ /dev/null @@ -1,31 +0,0 @@ -

278. First Bad Version

Easy


You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

- -

Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.

- -

You are given an API bool isBadVersion(version) which returns whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

- -

 

-

Example 1:

- -
Input: n = 5, bad = 4
-Output: 4
-Explanation:
-call isBadVersion(3) -> false
-call isBadVersion(5) -> true
-call isBadVersion(4) -> true
-Then 4 is the first bad version.
-
- -

Example 2:

- -
Input: n = 1, bad = 1
-Output: 1
-
- -

 

-

Constraints:

- -
    -
  • 1 <= bad <= n <= 231 - 1
  • -
-
\ No newline at end of file diff --git a/0297-serialize-and-deserialize-binary-tree/0297-serialize-and-deserialize-binary-tree.cpp b/0297-serialize-and-deserialize-binary-tree/0297-serialize-and-deserialize-binary-tree.cpp deleted file mode 100644 index 72d881e..0000000 --- a/0297-serialize-and-deserialize-binary-tree/0297-serialize-and-deserialize-binary-tree.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*struct TreeNode { -int val; -TreeNode *left; -TreeNode *right; -TreeNode(int x) : val(x), left(NULL), right(NULL) {} -}; -*/ - -class Codec { -public: - -// Encodes a tree to a single string. -string serialize(TreeNode* root) { - if(!root){return "";} - string s=""; - queueq; - q.push(root); - while(!q.empty()){ - TreeNode* r=q.front(); - q.pop(); - if(!r){s+="#,";} - else{s+=(to_string(r->val)+",");} - if(r!=NULL){ - q.push(r->left); - q.push(r->right); - } - } - return s; -} - -// Decodes your encoded data to tree. -TreeNode* deserialize(string data) { - if(data.size()==0){return NULL;} - stringstream x(data); - string str=""; - getline(x, str, ','); - TreeNode* root=new TreeNode(stoi(str)); - queueq; - q.push(root); - while(!q.empty()){ - TreeNode* rt=q.front(); - q.pop(); - getline(x, str, ','); - if(str=="#"){ - rt->left=NULL; - } - else{ - TreeNode* lft=new TreeNode(stoi(str)); - rt->left=lft; - q.push(lft); - } - getline(x, str, ','); - if(str=="#"){rt->right=NULL;} - else{ - TreeNode* rgt=new TreeNode(stoi(str)); - rt->right=rgt; - q.push(rgt); - } - } - return root; -} -}; - -// Your Codec object will be instantiated and called as such: -// Codec ser, deser; -// TreeNode* ans = deser.deserialize(ser.serialize(root)); diff --git a/0297-serialize-and-deserialize-binary-tree/README.md b/0297-serialize-and-deserialize-binary-tree/README.md deleted file mode 100644 index e423e52..0000000 --- a/0297-serialize-and-deserialize-binary-tree/README.md +++ /dev/null @@ -1,27 +0,0 @@ -

297. Serialize and Deserialize Binary Tree

Hard


Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

- -

Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.

- -

Clarification: The input/output format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.

- -

 

-

Example 1:

- -
Input: root = [1,2,3,null,null,4,5]
-Output: [1,2,3,null,null,4,5]
-
- -

Example 2:

- -
Input: root = []
-Output: []
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 104].
  • -
  • -1000 <= Node.val <= 1000
  • -
-
\ No newline at end of file diff --git a/0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.cpp b/0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.cpp deleted file mode 100644 index e0b6209..0000000 --- a/0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - int lengthOfLIS(vector& nums) { - int n = nums.size(); - int len; - vector> dp(n+1, vector(n+1,0)); - - for(int ind = n-1;ind>=0;ind--){ - for(int preInd = ind-1; preInd>=-1;preInd--){ - len = 0 + dp[ind+1][preInd+1]; - - if(preInd==-1 || nums[ind]>nums[preInd]) - len = max(len,1+dp[ind+1][ind+1]); - - dp[ind][preInd+1] = len; - } - } - return dp[0][0]; - } -}; \ No newline at end of file diff --git a/0300-longest-increasing-subsequence/NOTES.md b/0300-longest-increasing-subsequence/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0300-longest-increasing-subsequence/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0300-longest-increasing-subsequence/README.md b/0300-longest-increasing-subsequence/README.md deleted file mode 100644 index 80d6500..0000000 --- a/0300-longest-increasing-subsequence/README.md +++ /dev/null @@ -1,35 +0,0 @@ -

300. Longest Increasing Subsequence

Medium


Given an integer array nums, return the length of the longest strictly increasing subsequence.

- -

A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, [3,6,2,7] is a subsequence of the array [0,3,1,6,2,2,7].

- -

 

-

Example 1:

- -
Input: nums = [10,9,2,5,3,7,101,18]
-Output: 4
-Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
-
- -

Example 2:

- -
Input: nums = [0,1,0,3,2,3]
-Output: 4
-
- -

Example 3:

- -
Input: nums = [7,7,7,7,7,7,7]
-Output: 1
-
- -

 

-

Constraints:

- -
    -
  • 1 <= nums.length <= 2500
  • -
  • -104 <= nums[i] <= 104
  • -
- -

 

-

Follow up: Can you come up with an algorithm that runs in O(n log(n)) time complexity?

-
\ No newline at end of file diff --git a/0367-valid-perfect-square/0367-valid-perfect-square.cpp b/0367-valid-perfect-square/0367-valid-perfect-square.cpp deleted file mode 100644 index 4a988f4..0000000 --- a/0367-valid-perfect-square/0367-valid-perfect-square.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - bool isPerfectSquare(int num) { - int i=1, j=num; - while(i<=j){ - int mid=i+(j-i)/2; - //cout<367. Valid Perfect Square

Easy


Given a positive integer num, write a function which returns True if num is a perfect square else False.

- -

Follow up: Do not use any built-in library function such as sqrt.

- -

 

-

Example 1:

-
Input: num = 16
-Output: true
-

Example 2:

-
Input: num = 14
-Output: false
-
-

 

-

Constraints:

- -
    -
  • 1 <= num <= 2^31 - 1
  • -
-
\ No newline at end of file diff --git a/0374-guess-number-higher-or-lower/0374-guess-number-higher-or-lower.cpp b/0374-guess-number-higher-or-lower/0374-guess-number-higher-or-lower.cpp deleted file mode 100644 index 7547d0c..0000000 --- a/0374-guess-number-higher-or-lower/0374-guess-number-higher-or-lower.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Forward declaration of guess API. - * @param num your guess - * @return -1 if num is higher than the picked number - * 1 if num is lower than the picked number - * otherwise return 0 - * int guess(int num); - */ - -class Solution { -public: - int guessNumber(int n) { - - int l=0, h = n, mid; - - while(l<=h){ - - mid = l + (h-l)/2; - - int pick = guess(mid); - - if(pick==0) - return mid; - - else if(pick==1) - l = mid+1; - - else if(pick == -1) - h = mid-1; - - } - return -1; - } -}; \ No newline at end of file diff --git a/0374-guess-number-higher-or-lower/NOTES.md b/0374-guess-number-higher-or-lower/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0374-guess-number-higher-or-lower/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0374-guess-number-higher-or-lower/README.md b/0374-guess-number-higher-or-lower/README.md deleted file mode 100644 index 0d21ad8..0000000 --- a/0374-guess-number-higher-or-lower/README.md +++ /dev/null @@ -1,43 +0,0 @@ -

374. Guess Number Higher or Lower

Easy


We are playing the Guess Game. The game is as follows:

- -

I pick a number from 1 to n. You have to guess which number I picked.

- -

Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.

- -

You call a pre-defined API int guess(int num), which returns three possible results:

- -
    -
  • -1: Your guess is higher than the number I picked (i.e. num > pick).
  • -
  • 1: Your guess is lower than the number I picked (i.e. num < pick).
  • -
  • 0: your guess is equal to the number I picked (i.e. num == pick).
  • -
- -

Return the number that I picked.

- -

 

-

Example 1:

- -
Input: n = 10, pick = 6
-Output: 6
-
- -

Example 2:

- -
Input: n = 1, pick = 1
-Output: 1
-
- -

Example 3:

- -
Input: n = 2, pick = 1
-Output: 1
-
- -

 

-

Constraints:

- -
    -
  • 1 <= n <= 231 - 1
  • -
  • 1 <= pick <= n
  • -
-
\ No newline at end of file diff --git a/0392-is-subsequence/0392-is-subsequence.cpp b/0392-is-subsequence/0392-is-subsequence.cpp deleted file mode 100644 index fd65068..0000000 --- a/0392-is-subsequence/0392-is-subsequence.cpp +++ /dev/null @@ -1,37 +0,0 @@ -class Solution { -public: - bool isSubsequence(string text1, string text2) { - - int n = text1.size() , m = text2.size(); - int i,j; - // int ans = 0; - - vector> dp(n+1, vector(m+1,0)); - - for(i=0;i<=n;i++) - dp[i][0] = 0; - - for(j=0;j<=m;j++) - dp[0][j] = 0; - - for(i=1;i<=n;i++){ - for(j=1;j<=m;j++){ - - if(text1[i-1] == text2[j-1]){ - dp[i][j] = 1+ dp[i-1][j-1]; - // ans = max(ans,dp[i][j]); - } - - else - dp[i][j] = max(dp[i-1][j], dp[i][j-1]); - } - } - - - // cout<< dp[n][m]; - if(dp[n][m] == n) - return true; - - return false; - } -}; \ No newline at end of file diff --git a/0392-is-subsequence/NOTES.md b/0392-is-subsequence/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0392-is-subsequence/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0392-is-subsequence/README.md b/0392-is-subsequence/README.md deleted file mode 100644 index 56e9b40..0000000 --- a/0392-is-subsequence/README.md +++ /dev/null @@ -1,23 +0,0 @@ -

392. Is Subsequence

Easy


Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

- -

A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

- -

 

-

Example 1:

-
Input: s = "abc", t = "ahbgdc"
-Output: true
-

Example 2:

-
Input: s = "axc", t = "ahbgdc"
-Output: false
-
-

 

-

Constraints:

- -
    -
  • 0 <= s.length <= 100
  • -
  • 0 <= t.length <= 104
  • -
  • s and t consist only of lowercase English letters.
  • -
- -

 

-Follow up: Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code?
\ No newline at end of file diff --git a/0412-fizz-buzz/0412-fizz-buzz.cpp b/0412-fizz-buzz/0412-fizz-buzz.cpp deleted file mode 100644 index e32ece6..0000000 --- a/0412-fizz-buzz/0412-fizz-buzz.cpp +++ /dev/null @@ -1,25 +0,0 @@ -class Solution { -public: - vector fizzBuzz(int n) { - vector fizz; - - int i; - - for(int i=1; i<=n; i++){ - if(i%3==0 && i%5==0) - fizz.push_back("FizzBuzz"); - - else if(i%3==0 && i%5!=0) - fizz.push_back("Fizz"); - - else if(i%3!=0 && i%5==0) - fizz.push_back("Buzz"); - - else { - string str = to_string(i); - fizz.push_back(str); - } - } - return fizz; - } -}; \ No newline at end of file diff --git a/0412-fizz-buzz/NOTES.md b/0412-fizz-buzz/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0412-fizz-buzz/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0412-fizz-buzz/README.md b/0412-fizz-buzz/README.md deleted file mode 100644 index 09a0868..0000000 --- a/0412-fizz-buzz/README.md +++ /dev/null @@ -1,27 +0,0 @@ -

412. Fizz Buzz

Easy


Given an integer n, return a string array answer (1-indexed) where:

- -
    -
  • answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
  • -
  • answer[i] == "Fizz" if i is divisible by 3.
  • -
  • answer[i] == "Buzz" if i is divisible by 5.
  • -
  • answer[i] == i (as a string) if none of the above conditions are true.
  • -
- -

 

-

Example 1:

-
Input: n = 3
-Output: ["1","2","Fizz"]
-

Example 2:

-
Input: n = 5
-Output: ["1","2","Fizz","4","Buzz"]
-

Example 3:

-
Input: n = 15
-Output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
-
-

 

-

Constraints:

- -
    -
  • 1 <= n <= 104
  • -
-
\ No newline at end of file diff --git a/0449-serialize-and-deserialize-bst/0449-serialize-and-deserialize-bst.cpp b/0449-serialize-and-deserialize-bst/0449-serialize-and-deserialize-bst.cpp deleted file mode 100644 index 72d881e..0000000 --- a/0449-serialize-and-deserialize-bst/0449-serialize-and-deserialize-bst.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*struct TreeNode { -int val; -TreeNode *left; -TreeNode *right; -TreeNode(int x) : val(x), left(NULL), right(NULL) {} -}; -*/ - -class Codec { -public: - -// Encodes a tree to a single string. -string serialize(TreeNode* root) { - if(!root){return "";} - string s=""; - queueq; - q.push(root); - while(!q.empty()){ - TreeNode* r=q.front(); - q.pop(); - if(!r){s+="#,";} - else{s+=(to_string(r->val)+",");} - if(r!=NULL){ - q.push(r->left); - q.push(r->right); - } - } - return s; -} - -// Decodes your encoded data to tree. -TreeNode* deserialize(string data) { - if(data.size()==0){return NULL;} - stringstream x(data); - string str=""; - getline(x, str, ','); - TreeNode* root=new TreeNode(stoi(str)); - queueq; - q.push(root); - while(!q.empty()){ - TreeNode* rt=q.front(); - q.pop(); - getline(x, str, ','); - if(str=="#"){ - rt->left=NULL; - } - else{ - TreeNode* lft=new TreeNode(stoi(str)); - rt->left=lft; - q.push(lft); - } - getline(x, str, ','); - if(str=="#"){rt->right=NULL;} - else{ - TreeNode* rgt=new TreeNode(stoi(str)); - rt->right=rgt; - q.push(rgt); - } - } - return root; -} -}; - -// Your Codec object will be instantiated and called as such: -// Codec ser, deser; -// TreeNode* ans = deser.deserialize(ser.serialize(root)); diff --git a/0449-serialize-and-deserialize-bst/NOTES.md b/0449-serialize-and-deserialize-bst/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0449-serialize-and-deserialize-bst/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0449-serialize-and-deserialize-bst/README.md b/0449-serialize-and-deserialize-bst/README.md deleted file mode 100644 index f752585..0000000 --- a/0449-serialize-and-deserialize-bst/README.md +++ /dev/null @@ -1,23 +0,0 @@ -

449. Serialize and Deserialize BST

Medium


Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

- -

Design an algorithm to serialize and deserialize a binary search tree. There is no restriction on how your serialization/deserialization algorithm should work. You need to ensure that a binary search tree can be serialized to a string, and this string can be deserialized to the original tree structure.

- -

The encoded string should be as compact as possible.

- -

 

-

Example 1:

-
Input: root = [2,1,3]
-Output: [2,1,3]
-

Example 2:

-
Input: root = []
-Output: []
-
-

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 104].
  • -
  • 0 <= Node.val <= 104
  • -
  • The input tree is guaranteed to be a binary search tree.
  • -
-
\ No newline at end of file diff --git a/0450-delete-node-in-a-bst/0450-delete-node-in-a-bst.cpp b/0450-delete-node-in-a-bst/0450-delete-node-in-a-bst.cpp deleted file mode 100644 index 8092aa8..0000000 --- a/0450-delete-node-in-a-bst/0450-delete-node-in-a-bst.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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: - -TreeNode* deleteNode(TreeNode* root, int key) { - if(root==NULL){return NULL;} - if(root->val==key){return rmv(root);} - TreeNode* r=root; - while(r!=NULL){ - if(r->val>key){ - if(r->left!=NULL && r->left->val==key){ - r->left=rmv(r->left); - } - else{r=r->left;} - } - else{ - if(r->right!=NULL && r->right->val==key){ - r->right=rmv(r->right); - } - else{ - r=r->right; - } - } - } - return root; -} -TreeNode* rmv(TreeNode* node){ - if(node->left==NULL){return node->right;} - if(node->right==NULL){return node->left;} - TreeNode* rgt=node->right; - TreeNode* lft=rgtmst(node->left); - lft->right=rgt; - return node->left; -} -TreeNode* rgtmst(TreeNode* rt){ - if(rt->right==NULL){return rt;} - return rgtmst(rt->right); -} -}; \ No newline at end of file diff --git a/0450-delete-node-in-a-bst/NOTES.md b/0450-delete-node-in-a-bst/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0450-delete-node-in-a-bst/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0450-delete-node-in-a-bst/README.md b/0450-delete-node-in-a-bst/README.md deleted file mode 100644 index 78cf6d0..0000000 --- a/0450-delete-node-in-a-bst/README.md +++ /dev/null @@ -1,47 +0,0 @@ -

450. Delete Node in a BST

Medium


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

- -

Basically, the deletion can be divided into two stages:

- -
    -
  1. Search for a node to remove.
  2. -
  3. If the node is found, delete the node.
  4. -
- -

 

-

Example 1:

- -
Input: root = [5,3,6,2,4,null,7], key = 3
-Output: [5,4,6,2,null,null,7]
-Explanation: Given key to delete is 3. So we find the node with value 3 and delete it.
-One valid answer is [5,4,6,2,null,null,7], shown in the above BST.
-Please notice that another valid answer is [5,2,6,null,4,null,7] and it's also accepted.
-
-
- -

Example 2:

- -
Input: root = [5,3,6,2,4,null,7], key = 0
-Output: [5,3,6,2,4,null,7]
-Explanation: The tree does not contain a node with value = 0.
-
- -

Example 3:

- -
Input: root = [], key = 0
-Output: []
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [0, 104].
  • -
  • -105 <= Node.val <= 105
  • -
  • Each node has a unique value.
  • -
  • root is a valid binary search tree.
  • -
  • -105 <= key <= 105
  • -
- -

 

-

Follow up: Could you solve it with time complexity O(height of tree)?

-
\ No newline at end of file diff --git a/0501-find-mode-in-binary-search-tree/0501-find-mode-in-binary-search-tree.cpp b/0501-find-mode-in-binary-search-tree/0501-find-mode-in-binary-search-tree.cpp deleted file mode 100644 index 2453522..0000000 --- a/0501-find-mode-in-binary-search-tree/0501-find-mode-in-binary-search-tree.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { - private: - void finding(TreeNode* root,unordered_map&mp){ - if(root==NULL){ - return ; - } - mp[root->val]++; - finding(root->left,mp); - finding(root->right,mp); - } -public: - vector findMode(TreeNode* root) { - unordered_mapmp; - finding(root,mp); - int maxvalue=INT_MIN; - vectorans; - for(auto i:mp){ - if(maxvalue> res; - - // if(root==NULL) - // return res[]; - int ans; - queue nodesQueue; - nodesQueue.push(root); - - while(!nodesQueue.empty()){ - int size = nodesQueue.size(); - vector row(size); - - for(int i = 0;ival); - - if(node->left) - nodesQueue.push(node->left); - - if(node->right) - nodesQueue.push(node->right); - - } - // res.push_back(row); - ans = row[0]; - } - // int n = res.size()-1; - // return res[n][0]; - return ans; - } -}; \ No newline at end of file diff --git a/0513-find-bottom-left-tree-value/NOTES.md b/0513-find-bottom-left-tree-value/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0513-find-bottom-left-tree-value/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0513-find-bottom-left-tree-value/README.md b/0513-find-bottom-left-tree-value/README.md deleted file mode 100644 index a733cb6..0000000 --- a/0513-find-bottom-left-tree-value/README.md +++ /dev/null @@ -1,23 +0,0 @@ -

513. Find Bottom Left Tree Value

Medium


Given the root of a binary tree, return the leftmost value in the last row of the tree.

- -

 

-

Example 1:

- -
Input: root = [2,1,3]
-Output: 1
-
- -

Example 2:

- -
Input: root = [1,2,3,4,null,5,6,null,null,7]
-Output: 7
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 104].
  • -
  • -231 <= Node.val <= 231 - 1
  • -
-
\ No newline at end of file diff --git a/0515-find-largest-value-in-each-tree-row/0515-find-largest-value-in-each-tree-row.cpp b/0515-find-largest-value-in-each-tree-row/0515-find-largest-value-in-each-tree-row.cpp deleted file mode 100644 index 33a8b85..0000000 --- a/0515-find-largest-value-in-each-tree-row/0515-find-largest-value-in-each-tree-row.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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: - vector largestValues(TreeNode* root) { - - vector res; - - if(root==NULL) - return res; - - queue nodesQueue; - nodesQueue.push(root); - - while(!nodesQueue.empty()){ - - int size = nodesQueue.size(); - int maxi=INT_MIN; - - for(int i = 0;ival); - - if(node->left) - nodesQueue.push(node->left); - - if(node->right) - nodesQueue.push(node->right); - } - res.push_back(maxi); - } - - return res; - } -}; \ No newline at end of file diff --git a/0515-find-largest-value-in-each-tree-row/NOTES.md b/0515-find-largest-value-in-each-tree-row/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0515-find-largest-value-in-each-tree-row/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0521-longest-uncommon-subsequence-i/0521-longest-uncommon-subsequence-i.cpp b/0521-longest-uncommon-subsequence-i/0521-longest-uncommon-subsequence-i.cpp deleted file mode 100644 index d29b9f3..0000000 --- a/0521-longest-uncommon-subsequence-i/0521-longest-uncommon-subsequence-i.cpp +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - int findLUSlength(string text1, string text2) { - int n = text1.size() , m = text2.size(); - - if(text1==text2) - return -1; - - else if(n==m && text1!=text2) - return n; - - return max(n,m); - - // return -1; - } -}; \ No newline at end of file diff --git a/0521-longest-uncommon-subsequence-i/NOTES.md b/0521-longest-uncommon-subsequence-i/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0521-longest-uncommon-subsequence-i/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0521-longest-uncommon-subsequence-i/README.md b/0521-longest-uncommon-subsequence-i/README.md deleted file mode 100644 index 981c6ed..0000000 --- a/0521-longest-uncommon-subsequence-i/README.md +++ /dev/null @@ -1,41 +0,0 @@ -

521. Longest Uncommon Subsequence I

Easy


Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If the longest uncommon subsequence does not exist, return -1.

- -

An uncommon subsequence between two strings is a string that is a subsequence of one but not the other.

- -

A subsequence of a string s is a string that can be obtained after deleting any number of characters from s.

- -
    -
  • For example, "abc" is a subsequence of "aebdc" because you can delete the underlined characters in "aebdc" to get "abc". Other subsequences of "aebdc" include "aebdc", "aeb", and "" (empty string).
  • -
- -

 

-

Example 1:

- -
Input: a = "aba", b = "cdc"
-Output: 3
-Explanation: One longest uncommon subsequence is "aba" because "aba" is a subsequence of "aba" but not "cdc".
-Note that "cdc" is also a longest uncommon subsequence.
-
- -

Example 2:

- -
Input: a = "aaa", b = "bbb"
-Output: 3
-Explanation: The longest uncommon subsequences are "aaa" and "bbb".
-
- -

Example 3:

- -
Input: a = "aaa", b = "aaa"
-Output: -1
-Explanation: Every subsequence of string a is also a subsequence of string b. Similarly, every subsequence of string b is also a subsequence of string a.
-
- -

 

-

Constraints:

- -
    -
  • 1 <= a.length, b.length <= 100
  • -
  • a and b consist of lower-case English letters.
  • -
-
\ No newline at end of file diff --git a/0543-diameter-of-binary-tree/0543-diameter-of-binary-tree.cpp b/0543-diameter-of-binary-tree/0543-diameter-of-binary-tree.cpp deleted file mode 100644 index be1937a..0000000 --- a/0543-diameter-of-binary-tree/0543-diameter-of-binary-tree.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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: - - int chk(TreeNode* root, int& cnt){ - if(root==NULL){return 0;} - int l=chk(root->left, cnt); - int r=chk(root->right, cnt); - cnt=max(cnt, l+r); - return 1+max(l,r); -} - - int diameterOfBinaryTree(TreeNode* root) { - int cnt=0; - chk(root, cnt); - return cnt; -} - -}; -// }; \ No newline at end of file diff --git a/0543-diameter-of-binary-tree/NOTES.md b/0543-diameter-of-binary-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0543-diameter-of-binary-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0543-diameter-of-binary-tree/README.md b/0543-diameter-of-binary-tree/README.md deleted file mode 100644 index 26e6fc3..0000000 --- a/0543-diameter-of-binary-tree/README.md +++ /dev/null @@ -1,28 +0,0 @@ -

543. Diameter of Binary Tree

Easy


Given the root of a binary tree, return the length of the diameter of the tree.

- -

The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.

- -

The length of a path between two nodes is represented by the number of edges between them.

- -

 

-

Example 1:

- -
Input: root = [1,2,3,4,5]
-Output: 3
-Explanation: 3 is the length of the path [4,2,1,3] or [5,2,1,3].
-
- -

Example 2:

- -
Input: root = [1,2]
-Output: 1
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 104].
  • -
  • -100 <= Node.val <= 100
  • -
-
\ No newline at end of file diff --git a/0633-sum-of-square-numbers/0633-sum-of-square-numbers.cpp b/0633-sum-of-square-numbers/0633-sum-of-square-numbers.cpp deleted file mode 100644 index a8b201a..0000000 --- a/0633-sum-of-square-numbers/0633-sum-of-square-numbers.cpp +++ /dev/null @@ -1,23 +0,0 @@ -class Solution { -public: - - bool judgeSquareSum(int c) { - - // if(c==0) - // return true; - - long long k = sqrt(c);; - long long i = 0; - while(i<=k){ - if(i*i + k*k == c) - return true; - - else if(i*i + k*k > c) - k--; - - else if(i*i + k*k < c) - i++; - } - return false; - } -}; \ No newline at end of file diff --git a/0633-sum-of-square-numbers/README.md b/0633-sum-of-square-numbers/README.md deleted file mode 100644 index efeadaa..0000000 --- a/0633-sum-of-square-numbers/README.md +++ /dev/null @@ -1,23 +0,0 @@ -

633. Sum of Square Numbers

Medium


Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.

- -

 

-

Example 1:

- -
Input: c = 5
-Output: true
-Explanation: 1 * 1 + 2 * 2 = 5
-
- -

Example 2:

- -
Input: c = 3
-Output: false
-
- -

 

-

Constraints:

- -
    -
  • 0 <= c <= 231 - 1
  • -
-
\ No newline at end of file diff --git a/0637-average-of-levels-in-binary-tree/0637-average-of-levels-in-binary-tree.cpp b/0637-average-of-levels-in-binary-tree/0637-average-of-levels-in-binary-tree.cpp deleted file mode 100644 index 90d57ea..0000000 --- a/0637-average-of-levels-in-binary-tree/0637-average-of-levels-in-binary-tree.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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: - vector averageOfLevels(TreeNode* root) { - vector res; - - if(root==NULL) - return res; - - queue nodesQueue; - nodesQueue.push(root); - - while(!nodesQueue.empty()){ - int size = nodesQueue.size(); - vector row(size); - double sum = 0; - for(int i = 0;ival); - sum+= node->val; - - if(node->left) - nodesQueue.push(node->left); - - if(node->right) - nodesQueue.push(node->right); - - } - int avg = row.size(); - res.push_back(sum/avg); - } - -// int nn = res.size(); -// vector> ans; - - -// for(int i=nn-1;i>=0;i--){ -// vector tree; -// for(int j = 0;j637. Average of Levels in Binary Tree

Easy


Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer will be accepted. -

 

-

Example 1:

- -
Input: root = [3,9,20,null,null,15,7]
-Output: [3.00000,14.50000,11.00000]
-Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11.
-Hence return [3, 14.5, 11].
-
- -

Example 2:

- -
Input: root = [3,9,20,15,7]
-Output: [3.00000,14.50000,11.00000]
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 104].
  • -
  • -231 <= Node.val <= 231 - 1
  • -
-
\ No newline at end of file diff --git a/0645-set-mismatch/0645-set-mismatch.cpp b/0645-set-mismatch/0645-set-mismatch.cpp deleted file mode 100644 index b10d3bb..0000000 --- a/0645-set-mismatch/0645-set-mismatch.cpp +++ /dev/null @@ -1,42 +0,0 @@ -class Solution { -public: - vector findErrorNums(vector& nums) { - - int i, e=1; - vector set(2); - bool found = false; - int miss=-1, dup=-1, dupInd; - sort(nums.begin(), nums.end()); - - for(i=1;i& nums, int l, int r) - { - if(l > r) return nullptr; - TreeNode* root = new TreeNode; - auto pos = max_element(nums.begin() + l, nums.begin() + r + 1); - root->val = *pos; - if(l <= r) - { - root->left = Recurse(nums, l, pos - nums.begin() -1); - root->right = Recurse(nums, pos - nums.begin() + 1, r); - } - return root; - } -public: - TreeNode* constructMaximumBinaryTree(vector& nums) { - return Recurse(nums, 0, nums.size() - 1); - } -}; \ No newline at end of file diff --git a/0654-maximum-binary-tree/NOTES.md b/0654-maximum-binary-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0654-maximum-binary-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0654-maximum-binary-tree/README.md b/0654-maximum-binary-tree/README.md deleted file mode 100644 index acc5307..0000000 --- a/0654-maximum-binary-tree/README.md +++ /dev/null @@ -1,42 +0,0 @@ -

654. Maximum Binary Tree

Medium


You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm:

- -
    -
  1. Create a root node whose value is the maximum value in nums.
  2. -
  3. Recursively build the left subtree on the subarray prefix to the left of the maximum value.
  4. -
  5. Recursively build the right subtree on the subarray suffix to the right of the maximum value.
  6. -
- -

Return the maximum binary tree built from nums.

- -

 

-

Example 1:

- -
Input: nums = [3,2,1,6,0,5]
-Output: [6,3,5,null,2,0,null,null,1]
-Explanation: The recursive calls are as follow:
-- The largest value in [3,2,1,6,0,5] is 6. Left prefix is [3,2,1] and right suffix is [0,5].
-    - The largest value in [3,2,1] is 3. Left prefix is [] and right suffix is [2,1].
-        - Empty array, so no child.
-        - The largest value in [2,1] is 2. Left prefix is [] and right suffix is [1].
-            - Empty array, so no child.
-            - Only one element, so child is a node with value 1.
-    - The largest value in [0,5] is 5. Left prefix is [0] and right suffix is [].
-        - Only one element, so child is a node with value 0.
-        - Empty array, so no child.
-
- -

Example 2:

- -
Input: nums = [3,2,1]
-Output: [3,null,2,null,1]
-
- -

 

-

Constraints:

- -
    -
  • 1 <= nums.length <= 1000
  • -
  • 0 <= nums[i] <= 1000
  • -
  • All integers in nums are unique.
  • -
-
\ No newline at end of file diff --git a/0662-maximum-width-of-binary-tree/0662-maximum-width-of-binary-tree.cpp b/0662-maximum-width-of-binary-tree/0662-maximum-width-of-binary-tree.cpp deleted file mode 100644 index bcf3cbf..0000000 --- a/0662-maximum-width-of-binary-tree/0662-maximum-width-of-binary-tree.cpp +++ /dev/null @@ -1,45 +0,0 @@ -class Solution { -public: - int widthOfBinaryTree(TreeNode* root) { - if(root == NULL) - return 0; - - int res = 1; - queue> q; - - // I am using intialising list - q.push({root, 0}); // also can use make_pair - - while(!q.empty()) - { - int cnt = q.size(); - // start is the index of root node for first level - int start = q.front().second; - int end = q.back().second; - - res = max(res,end-start + 1); - - for(int i = 0; i p = q.front(); - // we will use it while inserting it children - // left child will be 2 * idx + 1; - // right chils will be 2 * idx + 2; - int idx = p.second - start; - - q.pop(); - - // if left child exist - if(p.first->left != NULL) - q.push({p.first->left, (long long)2 * idx + 1}); - - // if right child exist - if(p.first->right != NULL) - q.push({p.first->right, (long long) 2 * idx + 2}); - } - } - - return res; - - } -}; \ No newline at end of file diff --git a/0662-maximum-width-of-binary-tree/NOTES.md b/0662-maximum-width-of-binary-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0662-maximum-width-of-binary-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0662-maximum-width-of-binary-tree/README.md b/0662-maximum-width-of-binary-tree/README.md deleted file mode 100644 index 3a8386e..0000000 --- a/0662-maximum-width-of-binary-tree/README.md +++ /dev/null @@ -1,38 +0,0 @@ -

662. Maximum Width of Binary Tree

Medium


Given the root of a binary tree, return the maximum width of the given tree.

- -

The maximum width of a tree is the maximum width among all levels.

- -

The width of one level is defined as the length between the end-nodes (the leftmost and rightmost non-null nodes), where the null nodes between the end-nodes that would be present in a complete binary tree extending down to that level are also counted into the length calculation.

- -

It is guaranteed that the answer will in the range of a 32-bit signed integer.

- -

 

-

Example 1:

- -
Input: root = [1,3,2,5,3,null,9]
-Output: 4
-Explanation: The maximum width exists in the third level with length 4 (5,3,null,9).
-
- -

Example 2:

- -
Input: root = [1,3,2,5,null,null,9,6,null,7]
-Output: 7
-Explanation: The maximum width exists in the fourth level with length 7 (6,null,null,null,null,null,7).
-
- -

Example 3:

- -
Input: root = [1,3,2,5]
-Output: 2
-Explanation: The maximum width exists in the second level with length 2 (3,2).
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 3000].
  • -
  • -100 <= Node.val <= 100
  • -
-
\ No newline at end of file diff --git a/0701-insert-into-a-binary-search-tree/0701-insert-into-a-binary-search-tree.cpp b/0701-insert-into-a-binary-search-tree/0701-insert-into-a-binary-search-tree.cpp deleted file mode 100644 index a001070..0000000 --- a/0701-insert-into-a-binary-search-tree/0701-insert-into-a-binary-search-tree.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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: - TreeNode* insertIntoBST(TreeNode* root, int val) { - - if(!root) - return new TreeNode(val); - - TreeNode* cur = root; - - while(true){ - - if(cur->val <= val){ - if(cur->right!=NULL) - cur = cur->right; - else{ - cur->right = new TreeNode(val); - break; - } - } - - else { - if(cur->left!=NULL) - cur = cur->left; - else{ - cur->left = new TreeNode(val); - break; - } - - } - } - return root; - } -}; \ No newline at end of file diff --git a/0701-insert-into-a-binary-search-tree/NOTES.md b/0701-insert-into-a-binary-search-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0701-insert-into-a-binary-search-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0701-insert-into-a-binary-search-tree/README.md b/0701-insert-into-a-binary-search-tree/README.md deleted file mode 100644 index e065dfe..0000000 --- a/0701-insert-into-a-binary-search-tree/README.md +++ /dev/null @@ -1,36 +0,0 @@ -

701. Insert into a Binary Search Tree

Medium


You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.

- -

Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.

- -

 

-

Example 1:

- -
Input: root = [4,2,7,1,3], val = 5
-Output: [4,2,7,1,3,5]
-Explanation: Another accepted tree is:
-
-
- -

Example 2:

- -
Input: root = [40,20,60,10,30,50,70], val = 25
-Output: [40,20,60,10,30,50,70,null,null,25]
-
- -

Example 3:

- -
Input: root = [4,2,7,1,3,null,null,null,null,null,null], val = 5
-Output: [4,2,7,1,3,5]
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree will be in the range [0, 104].
  • -
  • -108 <= Node.val <= 108
  • -
  • All the values Node.val are unique.
  • -
  • -108 <= val <= 108
  • -
  • It's guaranteed that val does not exist in the original BST.
  • -
-
\ No newline at end of file diff --git a/0704-binary-search/0704-binary-search.cpp b/0704-binary-search/0704-binary-search.cpp deleted file mode 100644 index 81ea491..0000000 --- a/0704-binary-search/0704-binary-search.cpp +++ /dev/null @@ -1,21 +0,0 @@ -class Solution { -public: - int search(vector& nums, int target) { - int l=0,h=nums.size()-1; - int mid; - - while(l<=h){ - mid = (l+h)/2; - - if(nums[mid]==target) - return mid; - - else if(nums[mid]>target) - h = mid-1; - - else if(nums[mid]704. Binary Search

Easy


Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.

- -

You must write an algorithm with O(log n) runtime complexity.

- -

 

-

Example 1:

- -
Input: nums = [-1,0,3,5,9,12], target = 9
-Output: 4
-Explanation: 9 exists in nums and its index is 4
-
- -

Example 2:

- -
Input: nums = [-1,0,3,5,9,12], target = 2
-Output: -1
-Explanation: 2 does not exist in nums so return -1
-
- -

 

-

Constraints:

- -
    -
  • 1 <= nums.length <= 104
  • -
  • -104 < nums[i], target < 104
  • -
  • All the integers in nums are unique.
  • -
  • nums is sorted in ascending order.
  • -
-
\ No newline at end of file diff --git a/0744-find-smallest-letter-greater-than-target/0744-find-smallest-letter-greater-than-target.cpp b/0744-find-smallest-letter-greater-than-target/0744-find-smallest-letter-greater-than-target.cpp deleted file mode 100644 index 47eafd0..0000000 --- a/0744-find-smallest-letter-greater-than-target/0744-find-smallest-letter-greater-than-target.cpp +++ /dev/null @@ -1,24 +0,0 @@ -class Solution { -public: - char nextGreatestLetter(vector& letters, char target) { - int l=0,h=letters.size()-1; - - int mid; - // char ans ="1"; - - while(l<=h){ - mid = l+(h-l)/2; - - if(target744. Find Smallest Letter Greater Than Target

Easy


You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters.

- -

Return the smallest character in letters that is lexicographically greater than target. If such a character does not exist, return the first character in letters.

- -

 

-

Example 1:

- -
Input: letters = ["c","f","j"], target = "a"
-Output: "c"
-Explanation: The smallest character that is lexicographically greater than 'a' in letters is 'c'.
-
- -

Example 2:

- -
Input: letters = ["c","f","j"], target = "c"
-Output: "f"
-Explanation: The smallest character that is lexicographically greater than 'c' in letters is 'f'.
-
- -

Example 3:

- -
Input: letters = ["x","x","y","y"], target = "z"
-Output: "x"
-Explanation: There are no characters in letters that is lexicographically greater than 'z' so we return letters[0].
-
- -

 

-

Constraints:

- -
    -
  • 2 <= letters.length <= 104
  • -
  • letters[i] is a lowercase English letter.
  • -
  • letters is sorted in non-decreasing order.
  • -
  • letters contains at least two different characters.
  • -
  • target is a lowercase English letter.
  • -
-
\ No newline at end of file diff --git a/0852-peak-index-in-a-mountain-array/0852-peak-index-in-a-mountain-array.cpp b/0852-peak-index-in-a-mountain-array/0852-peak-index-in-a-mountain-array.cpp deleted file mode 100644 index 4c0e314..0000000 --- a/0852-peak-index-in-a-mountain-array/0852-peak-index-in-a-mountain-array.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - int peakIndexInMountainArray(vector& nums) { - int l=0,h=nums.size()-1; - - int mid; - - while(l<=h){ - mid = (l+h)/2; - - // if(nums[mid]>nums[mid-1] && nums[mid]>nums[mid+1]) - // return mid; - - if(nums[mid]852. Peak Index in a Mountain Array

Medium


An array arr a mountain if the following properties hold:

- -
    -
  • arr.length >= 3
  • -
  • There exists some i with 0 < i < arr.length - 1 such that: -
      -
    • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
    • -
    • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
    • -
    -
  • -
- -

Given a mountain array arr, return the index i such that arr[0] < arr[1] < ... < arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].

- -

You must solve it in O(log(arr.length)) time complexity.

- -

 

-

Example 1:

- -
Input: arr = [0,1,0]
-Output: 1
-
- -

Example 2:

- -
Input: arr = [0,2,1,0]
-Output: 1
-
- -

Example 3:

- -
Input: arr = [0,10,5,2]
-Output: 1
-
- -

 

-

Constraints:

- -
    -
  • 3 <= arr.length <= 105
  • -
  • 0 <= arr[i] <= 106
  • -
  • arr is guaranteed to be a mountain array.
  • -
-
\ No newline at end of file diff --git a/0863-all-nodes-distance-k-in-binary-tree/0863-all-nodes-distance-k-in-binary-tree.cpp b/0863-all-nodes-distance-k-in-binary-tree/0863-all-nodes-distance-k-in-binary-tree.cpp deleted file mode 100644 index 13be3f0..0000000 --- a/0863-all-nodes-distance-k-in-binary-tree/0863-all-nodes-distance-k-in-binary-tree.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - - vector distanceK(TreeNode* root, TreeNode* target, int k) { - vectorans; - unordered_mapv; - queueq; - TreeNode* r=root; - q.push(r); - int cnt=0; - while(!q.empty()){ - r=q.front(); - q.pop(); - if(r->left!=NULL){v[r->left]=r; q.push(r->left);} - if(r->right!=NULL){v[r->right]=r; q.push(r->right);} - } - unordered_mapv1; - v1[target]=true; - queueq1; - q1.push(target); - while(!q1.empty()){ - int l=q1.size(); - if(cnt==k){break;} - cnt++; - for(int i=0; ileft!=NULL && !v1[t->left]){v1[t->left]=true; q1.push(t->left);} - if(t->right!=NULL && !v1[t->right]){v1[t->right]=true; q1.push(t->right);} - if(v[t]!=NULL && !v1[v[t]]){v1[v[t]]=true; q1.push(v[t]);} - } - } - while(!q1.empty()){ - TreeNode* x=q1.front(); - ans.push_back(x->val); - q1.pop(); - } - return ans; -} -}; \ No newline at end of file diff --git a/0863-all-nodes-distance-k-in-binary-tree/NOTES.md b/0863-all-nodes-distance-k-in-binary-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0863-all-nodes-distance-k-in-binary-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0987-vertical-order-traversal-of-a-binary-tree/0987-vertical-order-traversal-of-a-binary-tree.cpp b/0987-vertical-order-traversal-of-a-binary-tree/0987-vertical-order-traversal-of-a-binary-tree.cpp deleted file mode 100644 index 79705c4..0000000 --- a/0987-vertical-order-traversal-of-a-binary-tree/0987-vertical-order-traversal-of-a-binary-tree.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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: - vector> verticalTraversal(TreeNode* root) { - map< int, map< int, multiset>> nodes; - queue>> todo; - todo.push({root,{0,0}}); - - while(!todo.empty()){ - auto p = todo.front(); - todo.pop(); - TreeNode * node = p.first; - int x = p.second.first, y = p.second.second; - nodes[x][y].insert(node->val); - - if(node->left){ - todo.push({node->left,{x-1, y+1}}); - } - - if(node->right){ - todo.push({node->right, {x+1, y+1}}); - } - } - vector> ans; - - for(auto p : nodes){ - vector col; - for(auto q : p.second){ - col.insert(col.end(),q.second.begin(),q.second.end()); - } - ans.push_back(col); - } - - return ans; - } -}; \ No newline at end of file diff --git a/0987-vertical-order-traversal-of-a-binary-tree/NOTES.md b/0987-vertical-order-traversal-of-a-binary-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/0987-vertical-order-traversal-of-a-binary-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/0987-vertical-order-traversal-of-a-binary-tree/README.md b/0987-vertical-order-traversal-of-a-binary-tree/README.md deleted file mode 100644 index 6ca0339..0000000 --- a/0987-vertical-order-traversal-of-a-binary-tree/README.md +++ /dev/null @@ -1,50 +0,0 @@ -

987. Vertical Order Traversal of a Binary Tree

Hard


Given the root of a binary tree, calculate the vertical order traversal of the binary tree.

- -

For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).

- -

The vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.

- -

Return the vertical order traversal of the binary tree.

- -

 

-

Example 1:

- -
Input: root = [3,9,20,null,null,15,7]
-Output: [[9],[3,15],[20],[7]]
-Explanation:
-Column -1: Only node 9 is in this column.
-Column 0: Nodes 3 and 15 are in this column in that order from top to bottom.
-Column 1: Only node 20 is in this column.
-Column 2: Only node 7 is in this column.
- -

Example 2:

- -
Input: root = [1,2,3,4,5,6,7]
-Output: [[4],[2],[1,5,6],[3],[7]]
-Explanation:
-Column -2: Only node 4 is in this column.
-Column -1: Only node 2 is in this column.
-Column 0: Nodes 1, 5, and 6 are in this column.
-          1 is at the top, so it comes first.
-          5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.
-Column 1: Only node 3 is in this column.
-Column 2: Only node 7 is in this column.
-
- -

Example 3:

- -
Input: root = [1,2,3,4,6,5,7]
-Output: [[4],[2],[1,5,6],[3],[7]]
-Explanation:
-This case is the exact same as example 2, but with nodes 5 and 6 swapped.
-Note that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 1000].
  • -
  • 0 <= Node.val <= 1000
  • -
-
\ No newline at end of file diff --git a/1008-construct-binary-search-tree-from-preorder-traversal/1008-construct-binary-search-tree-from-preorder-traversal.cpp b/1008-construct-binary-search-tree-from-preorder-traversal/1008-construct-binary-search-tree-from-preorder-traversal.cpp deleted file mode 100644 index 512d57c..0000000 --- a/1008-construct-binary-search-tree-from-preorder-traversal/1008-construct-binary-search-tree-from-preorder-traversal.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/** - * 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: - TreeNode* bstFromPreorder(vector& preorder) { - int i=0; - return construction(preorder,i,INT_MAX); - } - - TreeNode* construction(vector& preorder,int &i,int bound) - { - if(i==preorder.size()||preorder[i]>bound) - { - return NULL; - } - TreeNode* root=new TreeNode(preorder[i]); - i++; - root->left=construction(preorder,i,root->val); - root->right=construction(preorder,i,bound); - return root; - } -}; \ No newline at end of file diff --git a/1008-construct-binary-search-tree-from-preorder-traversal/README.md b/1008-construct-binary-search-tree-from-preorder-traversal/README.md deleted file mode 100644 index c4e7ecd..0000000 --- a/1008-construct-binary-search-tree-from-preorder-traversal/README.md +++ /dev/null @@ -1,30 +0,0 @@ -

1008. Construct Binary Search Tree from Preorder Traversal

Medium


Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root.

- -

It is guaranteed that there is always possible to find a binary search tree with the given requirements for the given test cases.

- -

A binary search tree is a binary tree where for every node, any descendant of Node.left has a value strictly less than Node.val, and any descendant of Node.right has a value strictly greater than Node.val.

- -

A preorder traversal of a binary tree displays the value of the node first, then traverses Node.left, then traverses Node.right.

- -

 

-

Example 1:

- -
Input: preorder = [8,5,1,7,10,12]
-Output: [8,5,10,1,7,null,12]
-
- -

Example 2:

- -
Input: preorder = [1,3]
-Output: [1,null,3]
-
- -

 

-

Constraints:

- -
    -
  • 1 <= preorder.length <= 100
  • -
  • 1 <= preorder[i] <= 1000
  • -
  • All the values of preorder are unique.
  • -
-
\ No newline at end of file diff --git a/1092-shortest-common-supersequence/1092-shortest-common-supersequence.cpp b/1092-shortest-common-supersequence/1092-shortest-common-supersequence.cpp deleted file mode 100644 index 090cc3c..0000000 --- a/1092-shortest-common-supersequence/1092-shortest-common-supersequence.cpp +++ /dev/null @@ -1,64 +0,0 @@ -class Solution { -public: - string shortestCommonSupersequence(string text1, string text2) { - - int n = text1.size() , m = text2.size(); - int i,j; - - vector> dp(n+1, vector(m+1,0)); - - for(i=0;i<=n;i++) - dp[i][0] = 0; - - for(j=0;j<=m;j++) - dp[0][j] = 0; - - for(i=1;i<=n;i++){ - for(j=1;j<=m;j++){ - - if(text1[i-1] == text2[j-1]) - dp[i][j] = 1+ dp[i-1][j-1]; - - else - dp[i][j] = max(dp[i-1][j], dp[i][j-1]); - } - } - // cout<< dp[n][m]; - string res = ""; - - i = n, j=m; - - while(i>0 && j>0){ - - if(text1[i-1] == text2[j-1]){ - res+=text1[i-1]; - i--; j--; - } - - else if(dp[i-1][j] > dp[i][j-1]){ // upper value - res+=text1[i-1]; - i--; - } - - else { - res+=text2[j-1]; - j--; - } - } - - while(i>0){ - res+= text1[i-1]; - i--; - } - - while(j>0){ - res+= text2[j-1]; - j--; - } - - reverse(res.begin(), res.end()); - - return res; - - } -}; \ No newline at end of file diff --git a/1092-shortest-common-supersequence/NOTES.md b/1092-shortest-common-supersequence/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/1092-shortest-common-supersequence/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/1092-shortest-common-supersequence/README.md b/1092-shortest-common-supersequence/README.md deleted file mode 100644 index f93f629..0000000 --- a/1092-shortest-common-supersequence/README.md +++ /dev/null @@ -1,29 +0,0 @@ -

1092. Shortest Common Supersequence

Hard


Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them.

- -

A string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s.

- -

 

-

Example 1:

- -
Input: str1 = "abac", str2 = "cab"
-Output: "cabac"
-Explanation: 
-str1 = "abac" is a subsequence of "cabac" because we can delete the first "c".
-str2 = "cab" is a subsequence of "cabac" because we can delete the last "ac".
-The answer provided is the shortest such string that satisfies these properties.
-
- -

Example 2:

- -
Input: str1 = "aaaaaaaa", str2 = "aaaaaaaa"
-Output: "aaaaaaaa"
-
- -

 

-

Constraints:

- -
    -
  • 1 <= str1.length, str2.length <= 1000
  • -
  • str1 and str2 consist of lowercase English letters.
  • -
-
\ No newline at end of file diff --git a/1143-longest-common-subsequence/1143-longest-common-subsequence.cpp b/1143-longest-common-subsequence/1143-longest-common-subsequence.cpp deleted file mode 100644 index fc47f5c..0000000 --- a/1143-longest-common-subsequence/1143-longest-common-subsequence.cpp +++ /dev/null @@ -1,29 +0,0 @@ -class Solution { -public: - int longestCommonSubsequence(string text1, string text2) { - - int n = text1.size() , m = text2.size(); - int i,j; - - vector> dp(n+1, vector(m+1,0)); - - for(i=0;i<=n;i++) - dp[i][0] = 0; - - for(j=0;j<=m;j++) - dp[0][j] = 0; - - for(i=1;i<=n;i++){ - for(j=1;j<=m;j++){ - - if(text1[i-1] == text2[j-1]) - dp[i][j] = 1+ dp[i-1][j-1]; - - else - dp[i][j] = max(dp[i-1][j], dp[i][j-1]); - } - } - - return dp[n][m]; - } -}; \ No newline at end of file diff --git a/1143-longest-common-subsequence/README.md b/1143-longest-common-subsequence/README.md deleted file mode 100644 index 4137156..0000000 --- a/1143-longest-common-subsequence/README.md +++ /dev/null @@ -1,40 +0,0 @@ -

1143. Longest Common Subsequence

Medium


Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

- -

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

- -
    -
  • For example, "ace" is a subsequence of "abcde".
  • -
- -

A common subsequence of two strings is a subsequence that is common to both strings.

- -

 

-

Example 1:

- -
Input: text1 = "abcde", text2 = "ace" 
-Output: 3  
-Explanation: The longest common subsequence is "ace" and its length is 3.
-
- -

Example 2:

- -
Input: text1 = "abc", text2 = "abc"
-Output: 3
-Explanation: The longest common subsequence is "abc" and its length is 3.
-
- -

Example 3:

- -
Input: text1 = "abc", text2 = "def"
-Output: 0
-Explanation: There is no such common subsequence, so the result is 0.
-
- -

 

-

Constraints:

- -
    -
  • 1 <= text1.length, text2.length <= 1000
  • -
  • text1 and text2 consist of only lowercase English characters.
  • -
-
\ No newline at end of file diff --git a/1161-maximum-level-sum-of-a-binary-tree/1161-maximum-level-sum-of-a-binary-tree.cpp b/1161-maximum-level-sum-of-a-binary-tree/1161-maximum-level-sum-of-a-binary-tree.cpp deleted file mode 100644 index 0564181..0000000 --- a/1161-maximum-level-sum-of-a-binary-tree/1161-maximum-level-sum-of-a-binary-tree.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/** - * 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: - int maxLevelSum(TreeNode* root) { - // vector> res; - int maxi=INT_MIN; - int level = 1,lvl; - // pair sumInd; - - if(root==NULL) - return level; - - queue nodesQueue; - nodesQueue.push(root); - - while(!nodesQueue.empty()){ - - int size = nodesQueue.size(); - // vector row(size); - int sum = 0; - - for(int i = 0;ival); - - if(node->left) - nodesQueue.push(node->left); - - if(node->right) - nodesQueue.push(node->right); - - } - if(maxi1161. Maximum Level Sum of a Binary Tree

Medium


Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.

- -

Return the smallest level x such that the sum of all the values of nodes at level x is maximal.

- -

 

-

Example 1:

- -
Input: root = [1,7,0,7,-8,null,null]
-Output: 2
-Explanation: 
-Level 1 sum = 1.
-Level 2 sum = 7 + 0 = 7.
-Level 3 sum = 7 + -8 = -1.
-So we return the level with the maximum sum which is level 2.
-
- -

Example 2:

- -
Input: root = [989,null,10250,98693,-89388,null,null,null,-32127]
-Output: 2
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 104].
  • -
  • -105 <= Node.val <= 105
  • -
-
\ No newline at end of file diff --git a/1312-minimum-insertion-steps-to-make-a-string-palindrome/1312-minimum-insertion-steps-to-make-a-string-palindrome.cpp b/1312-minimum-insertion-steps-to-make-a-string-palindrome/1312-minimum-insertion-steps-to-make-a-string-palindrome.cpp deleted file mode 100644 index e12de4c..0000000 --- a/1312-minimum-insertion-steps-to-make-a-string-palindrome/1312-minimum-insertion-steps-to-make-a-string-palindrome.cpp +++ /dev/null @@ -1,34 +0,0 @@ -class Solution { -public: - int minInsertions(string s) { - int n = s.size(); - string sr = s; - reverse(sr.begin(), sr.end()); - int i,j; - //int ans = 0; - - vector> dp(n+1, vector(n+1,0)); - - for(i=0;i<=n;i++) - dp[i][0] = 0; - - for(j=0;j<=n;j++) - dp[0][j] = 0; - - for(i=1;i<=n;i++){ - for(j=1;j<=n;j++){ - - if(s[i-1] == sr[j-1]){ - dp[i][j] = 1+ dp[i-1][j-1]; - // ans = max(ans,dp[i][j]); - } - - else - dp[i][j] = max(dp[i-1][j], dp[i][j-1]); - } - } - - int res = n - dp[n][n]; - return res; - } -}; \ No newline at end of file diff --git a/1312-minimum-insertion-steps-to-make-a-string-palindrome/NOTES.md b/1312-minimum-insertion-steps-to-make-a-string-palindrome/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/1312-minimum-insertion-steps-to-make-a-string-palindrome/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/1332-remove-palindromic-subsequences/1332-remove-palindromic-subsequences.cpp b/1332-remove-palindromic-subsequences/1332-remove-palindromic-subsequences.cpp deleted file mode 100644 index 31b1bc4..0000000 --- a/1332-remove-palindromic-subsequences/1332-remove-palindromic-subsequences.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - int removePalindromeSub(string s) { - int i=0, j=s.size()-1; - while(i1332. Remove Palindromic Subsequences

Easy


You are given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s.

- -

Return the minimum number of steps to make the given string empty.

- -

A string is a subsequence of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does not necessarily need to be contiguous.

- -

A string is called palindrome if is one that reads the same backward as well as forward.

- -

 

-

Example 1:

- -
Input: s = "ababa"
-Output: 1
-Explanation: s is already a palindrome, so its entirety can be removed in a single step.
-
- -

Example 2:

- -
Input: s = "abb"
-Output: 2
-Explanation: "abb" -> "bb" -> "". 
-Remove palindromic subsequence "a" then "bb".
-
- -

Example 3:

- -
Input: s = "baabb"
-Output: 2
-Explanation: "baabb" -> "b" -> "". 
-Remove palindromic subsequence "baab" then "b".
-
- -

 

-

Constraints:

- -
    -
  • 1 <= s.length <= 1000
  • -
  • s[i] is either 'a' or 'b'.
  • -
-
\ No newline at end of file diff --git a/1351-count-negative-numbers-in-a-sorted-matrix/1351-count-negative-numbers-in-a-sorted-matrix.cpp b/1351-count-negative-numbers-in-a-sorted-matrix/1351-count-negative-numbers-in-a-sorted-matrix.cpp deleted file mode 100644 index d00be11..0000000 --- a/1351-count-negative-numbers-in-a-sorted-matrix/1351-count-negative-numbers-in-a-sorted-matrix.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - int countNegatives(vector>& arr) { - int m = arr.size(), n = arr[0].size(); - int cnt = 0; - for(int i = 0;i= 0) low = mid+1; - } - // cout<1351. Count Negative Numbers in a Sorted Matrix

Easy


Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.

- -

 

-

Example 1:

- -
Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
-Output: 8
-Explanation: There are 8 negatives number in the matrix.
-
- -

Example 2:

- -
Input: grid = [[3,2],[1,0]]
-Output: 0
-
- -

 

-

Constraints:

- -
    -
  • m == grid.length
  • -
  • n == grid[i].length
  • -
  • 1 <= m, n <= 100
  • -
  • -100 <= grid[i][j] <= 100
  • -
- -

 

-Follow up: Could you find an O(n + m) solution?
\ No newline at end of file diff --git a/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree.cpp b/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree.cpp deleted file mode 100644 index 9288cd1..0000000 --- a/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ - -class Solution { - - void dfs(TreeNode* copy, TreeNode* target, TreeNode*& ans) { - if(!copy) return; - - if(copy->val == target->val) { - ans = copy; - } - - dfs(copy->left, target, ans); - dfs(copy->right, target, ans); - - return; - } - -public: - TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) { - - TreeNode* ans = nullptr; - dfs(cloned, target, ans); - return ans; - } -}; \ No newline at end of file diff --git a/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/NOTES.md b/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/README.md b/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/README.md deleted file mode 100644 index 4026ff8..0000000 --- a/1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/README.md +++ /dev/null @@ -1,40 +0,0 @@ -

1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree

Easy


Given two binary trees original and cloned and given a reference to a node target in the original tree.

- -

The cloned tree is a copy of the original tree.

- -

Return a reference to the same node in the cloned tree.

- -

Note that you are not allowed to change any of the two trees or the target node and the answer must be a reference to a node in the cloned tree.

- -

 

-

Example 1:

- -
Input: tree = [7,4,3,null,null,6,19], target = 3
-Output: 3
-Explanation: In all examples the original and cloned trees are shown. The target node is a green node from the original tree. The answer is the yellow node from the cloned tree.
-
- -

Example 2:

- -
Input: tree = [7], target =  7
-Output: 7
-
- -

Example 3:

- -
Input: tree = [8,null,6,null,5,null,4,null,3,null,2,null,1], target = 4
-Output: 4
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 104].
  • -
  • The values of the nodes of the tree are unique.
  • -
  • target node is a node from the original tree and is not null.
  • -
- -

 

-

Follow up: Could you solve the problem if repeated values on the tree are allowed?

-
\ No newline at end of file diff --git a/1609-even-odd-tree/1609-even-odd-tree.cpp b/1609-even-odd-tree/1609-even-odd-tree.cpp deleted file mode 100644 index a03634e..0000000 --- a/1609-even-odd-tree/1609-even-odd-tree.cpp +++ /dev/null @@ -1,47 +0,0 @@ -class Solution { -public: - bool isEvenOddTree(TreeNode* root) { - if(root==NULL) - return false; - queue q; - q.push(root); - int level=0; - - while(!q.empty()) - { - int size=q.size(); - vector temp; - - for(int i=0;ival); - if(front->left) - q.push(front->left); - if(front->right) - q.push(front->right); - } - if(level==0 || level%2==0){ -// Checking conditions for even level - for(int i=0;i=temp[i+1]) - return false; - } - else{ -// Checking conditions for odd level - for(int i=0;i1609. Even Odd Tree

Medium


A binary tree is named Even-Odd if it meets the following conditions:

- -
    -
  • The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.
  • -
  • For every even-indexed level, all nodes at the level have odd integer values in strictly increasing order (from left to right).
  • -
  • For every odd-indexed level, all nodes at the level have even integer values in strictly decreasing order (from left to right).
  • -
- -

Given the root of a binary tree, return true if the binary tree is Even-Odd, otherwise return false.

- -

 

-

Example 1:

- -
Input: root = [1,10,4,3,null,7,9,12,8,6,null,null,2]
-Output: true
-Explanation: The node values on each level are:
-Level 0: [1]
-Level 1: [10,4]
-Level 2: [3,7,9]
-Level 3: [12,8,6,2]
-Since levels 0 and 2 are all odd and increasing and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.
-
- -

Example 2:

- -
Input: root = [5,4,2,3,3,7]
-Output: false
-Explanation: The node values on each level are:
-Level 0: [5]
-Level 1: [4,2]
-Level 2: [3,3,7]
-Node values in level 2 must be in strictly increasing order, so the tree is not Even-Odd.
-
- -

Example 3:

- -
Input: root = [5,9,1,3,5,7]
-Output: false
-Explanation: Node values in the level 1 should be even integers.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 105].
  • -
  • 1 <= Node.val <= 106
  • -
-
\ No newline at end of file diff --git a/1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.cpp b/1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.cpp deleted file mode 100644 index 51ed678..0000000 --- a/1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.cpp +++ /dev/null @@ -1,24 +0,0 @@ -class Solution { -public: - bool arrayStringsAreEqual(vector& word1, vector& word2) { - - int n = word1.size(); - int m = word2.size(); - - string str1 = ""; - string str2 = ""; - - for(int i = 0 ; i1662. Check If Two String Arrays are Equivalent

Easy


Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.

- -

A string is represented by an array if the array elements concatenated in order forms the string.

- -

 

-

Example 1:

- -
Input: word1 = ["ab", "c"], word2 = ["a", "bc"]
-Output: true
-Explanation:
-word1 represents string "ab" + "c" -> "abc"
-word2 represents string "a" + "bc" -> "abc"
-The strings are the same, so return true.
- -

Example 2:

- -
Input: word1 = ["a", "cb"], word2 = ["ab", "c"]
-Output: false
-
- -

Example 3:

- -
Input: word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]
-Output: true
-
- -

 

-

Constraints:

- -
    -
  • 1 <= word1.length, word2.length <= 103
  • -
  • 1 <= word1[i].length, word2[i].length <= 103
  • -
  • 1 <= sum(word1[i].length), sum(word2[i].length) <= 103
  • -
  • word1[i] and word2[i] consist of lowercase letters.
  • -
-
\ No newline at end of file diff --git a/2236-root-equals-sum-of-children/2236-root-equals-sum-of-children.cpp b/2236-root-equals-sum-of-children/2236-root-equals-sum-of-children.cpp deleted file mode 100644 index 0cfe5ea..0000000 --- a/2236-root-equals-sum-of-children/2236-root-equals-sum-of-children.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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: - bool checkTree(TreeNode* root) { - // if(!root) - // return true; - - // int total = root->left->val + root->right->val; - - if(root->left->val + root->right->val==root->val) - return true; - - return false; - } -}; \ No newline at end of file diff --git a/2236-root-equals-sum-of-children/NOTES.md b/2236-root-equals-sum-of-children/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/2236-root-equals-sum-of-children/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/2236-root-equals-sum-of-children/README.md b/2236-root-equals-sum-of-children/README.md deleted file mode 100644 index 70879af..0000000 --- a/2236-root-equals-sum-of-children/README.md +++ /dev/null @@ -1,29 +0,0 @@ -

2236. Root Equals Sum of Children

Easy


You are given the root of a binary tree that consists of exactly 3 nodes: the root, its left child, and its right child.

- -

Return true if the value of the root is equal to the sum of the values of its two children, or false otherwise.

- -

 

-

Example 1:

- -
Input: root = [10,4,6]
-Output: true
-Explanation: The values of the root, its left child, and its right child are 10, 4, and 6, respectively.
-10 is equal to 4 + 6, so we return true.
-
- -

Example 2:

- -
Input: root = [5,3,1]
-Output: false
-Explanation: The values of the root, its left child, and its right child are 5, 3, and 1, respectively.
-5 is not equal to 3 + 1, so we return false.
-
- -

 

-

Constraints:

- -
    -
  • The tree consists only of the root, its left child, and its right child.
  • -
  • -100 <= Node.val <= 100
  • -
-
\ No newline at end of file diff --git a/2385-amount-of-time-for-binary-tree-to-be-infected/2385-amount-of-time-for-binary-tree-to-be-infected.cpp b/2385-amount-of-time-for-binary-tree-to-be-infected/2385-amount-of-time-for-binary-tree-to-be-infected.cpp deleted file mode 100644 index 752ccba..0000000 --- a/2385-amount-of-time-for-binary-tree-to-be-infected/2385-amount-of-time-for-binary-tree-to-be-infected.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/** - * 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 { -private: - TreeNode *createMapping(TreeNode* root, int start , map &nodeToParent){ - TreeNode *ans = NULL; - queue q; - q.push(root); - nodeToParent[root] = NULL; - - while(!q.empty()){ - TreeNode *front = q.front(); - q.pop(); - - if(front->val == start) - ans = front; - - if(front->left){ - nodeToParent[front->left] = front; - q.push(front->left); - } - if(front->right){ - nodeToParent[front->right] = front; - q.push(front->right); - } - } - return ans; - } - - void solve(TreeNode* root , map &nodeToParent , int &time){ - map visited; - queueq; - q.push(root); - visited[root] = 1; - - - while(!q.empty()){ - int size = q.size(); - bool flag = false; - - for(int i = 0 ; i < size ; i++){ - TreeNode *front = q.front(); - q.pop(); - - if(front->left && !visited[front->left]){ - flag = true; - visited[front->left] = 1; - q.push(front->left); - } - if(front->right && !visited[front->right]){ - flag = true; - visited[front->right] = 1; - q.push(front->right); - } - if(nodeToParent[front] && !visited[nodeToParent[front]]){ - flag = true; - visited[nodeToParent[front]] = 1; - q.push(nodeToParent[front]); - } - } - if(flag == true) - time++; - } - } - -public: - int amountOfTime(TreeNode* root, int start) { - - map nodeToParent; - TreeNode *target = createMapping(root , start , nodeToParent); - - - int time = 0; - solve(target , nodeToParent , time); - return time; - } -}; \ No newline at end of file diff --git a/2385-amount-of-time-for-binary-tree-to-be-infected/NOTES.md b/2385-amount-of-time-for-binary-tree-to-be-infected/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/2385-amount-of-time-for-binary-tree-to-be-infected/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/2385-amount-of-time-for-binary-tree-to-be-infected/README.md b/2385-amount-of-time-for-binary-tree-to-be-infected/README.md deleted file mode 100644 index 4c9f31b..0000000 --- a/2385-amount-of-time-for-binary-tree-to-be-infected/README.md +++ /dev/null @@ -1,42 +0,0 @@ -

2385. Amount of Time for Binary Tree to Be Infected

Medium


You are given the root of a binary tree with unique values, and an integer start. At minute 0, an infection starts from the node with value start.

- -

Each minute, a node becomes infected if:

- -
    -
  • The node is currently uninfected.
  • -
  • The node is adjacent to an infected node.
  • -
- -

Return the number of minutes needed for the entire tree to be infected.

- -

 

-

Example 1:

- -
Input: root = [1,5,3,null,4,10,6,9,2], start = 3
-Output: 4
-Explanation: The following nodes are infected during:
-- Minute 0: Node 3
-- Minute 1: Nodes 1, 10 and 6
-- Minute 2: Node 5
-- Minute 3: Node 4
-- Minute 4: Nodes 9 and 2
-It takes 4 minutes for the whole tree to be infected so we return 4.
-
- -

Example 2:

- -
Input: root = [1], start = 1
-Output: 0
-Explanation: At minute 0, the only node in the tree is infected so we return 0.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 105].
  • -
  • 1 <= Node.val <= 105
  • -
  • Each node has a unique value.
  • -
  • A node with a value of start exists in the tree.
  • -
-
\ No newline at end of file diff --git a/2415-reverse-odd-levels-of-binary-tree/2415-reverse-odd-levels-of-binary-tree.cpp b/2415-reverse-odd-levels-of-binary-tree/2415-reverse-odd-levels-of-binary-tree.cpp deleted file mode 100644 index dd6f798..0000000 --- a/2415-reverse-odd-levels-of-binary-tree/2415-reverse-odd-levels-of-binary-tree.cpp +++ /dev/null @@ -1,43 +0,0 @@ -class Solution -{ -public: - TreeNode* reverseOddLevels(TreeNode* root) - { - if(!root) return root; - - queue q; - vector values; - q.push(root); - int level=0; - - while(!q.empty()) - { - int sz = q.size(); - vector temp; - for(int i=0; ival = values[sz-i-1]; - - if(node->left) - { - q.push(node->left); - temp.push_back(node->left->val); - } - if(node->right) - { - q.push(node->right); - temp.push_back(node->right->val); - } - - } - values = temp; - level++; - } - return root; - - - } -}; \ No newline at end of file diff --git a/2415-reverse-odd-levels-of-binary-tree/README.md b/2415-reverse-odd-levels-of-binary-tree/README.md deleted file mode 100644 index 6b14748..0000000 --- a/2415-reverse-odd-levels-of-binary-tree/README.md +++ /dev/null @@ -1,49 +0,0 @@ -

2415. Reverse Odd Levels of Binary Tree

Medium


Given the root of a perfect binary tree, reverse the node values at each odd level of the tree.

- -
    -
  • For example, suppose the node values at level 3 are [2,1,3,4,7,11,29,18], then it should become [18,29,11,7,4,3,1,2].
  • -
- -

Return the root of the reversed tree.

- -

A binary tree is perfect if all parent nodes have two children and all leaves are on the same level.

- -

The level of a node is the number of edges along the path between it and the root node.

- -

 

-

Example 1:

- -
Input: root = [2,3,5,8,13,21,34]
-Output: [2,5,3,8,13,21,34]
-Explanation: 
-The tree has only one odd level.
-The nodes at level 1 are 3, 5 respectively, which are reversed and become 5, 3.
-
- -

Example 2:

- -
Input: root = [7,13,11]
-Output: [7,11,13]
-Explanation: 
-The nodes at level 1 are 13, 11, which are reversed and become 11, 13.
-
- -

Example 3:

- -
Input: root = [0,1,2,0,0,0,0,1,1,1,1,2,2,2,2]
-Output: [0,2,1,0,0,0,0,2,2,2,2,1,1,1,1]
-Explanation: 
-The odd levels have non-zero values.
-The nodes at level 1 were 1, 2, and are 2, 1 after the reversal.
-The nodes at level 3 were 1, 1, 1, 1, 2, 2, 2, 2, and are 2, 2, 2, 2, 1, 1, 1, 1 after the reversal.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 214].
  • -
  • 0 <= Node.val <= 105
  • -
  • root is a perfect binary tree.
  • -
-
\ No newline at end of file diff --git a/bestSightPair.cpp b/bestSightPair.cpp deleted file mode 100644 index de4f4ec..0000000 --- a/bestSightPair.cpp +++ /dev/null @@ -1,15 +0,0 @@ -class Solution { -public: - int maxScoreSightseeingPair(vector& values) { - int maxi = values[0]+0; - int ans = -1; - int i; - - for(i=1;i& prices) { - - int min= 100000; - int i; - int profit = -1; - - for(i=0;iprices[i]) - min = prices[i]; - - if(prices[i] - min > profit) - profit = prices[i] - min; - } - return profit; - } -}; \ No newline at end of file diff --git a/bestTimeToBuyAndSellStock2.cpp b/bestTimeToBuyAndSellStock2.cpp deleted file mode 100644 index c8d1926..0000000 --- a/bestTimeToBuyAndSellStock2.cpp +++ /dev/null @@ -1,12 +0,0 @@ -class Solution { -public: - int maxProfit(vector& prices) { - int i, profit=0; - - for(i=1;iprices[i-1]) - profit += (prices[i]-prices[i-1]); - } - return profit; - } -}; diff --git a/empty.cpp b/empty.cpp new file mode 100644 index 0000000..e69de29 diff --git a/fibonacciRecurrsion.cpp b/fibonacciRecurrsion.cpp deleted file mode 100644 index edfe339..0000000 --- a/fibonacciRecurrsion.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - - int f(int n){ - - if(n<=1){ - return n; - } - - int last = f(n-1); - int secondLast = f(n-2); - - return last + secondLast; - } - - - int fib(int n) { - return f(n); - } -}; \ No newline at end of file diff --git a/fibonacciTabulation.cpp b/fibonacciTabulation.cpp deleted file mode 100644 index 94b2f2c..0000000 --- a/fibonacciTabulation.cpp +++ /dev/null @@ -1,19 +0,0 @@ -class Solution { -public: - int fib(int n) { - int i; - - if (n ==0) - return 0; - - int dp[n+1]; - - dp[0] = 0; - dp[1] = 1; - - for(i=2;i<=n;i++) - dp[i] = dp[i-1] + dp[i-2]; - - return dp[n]; - } -}; \ No newline at end of file diff --git a/houseRobber2.cpp b/houseRobber2.cpp deleted file mode 100644 index 6e3a3c1..0000000 --- a/houseRobber2.cpp +++ /dev/null @@ -1,32 +0,0 @@ -class Solution { -public: - - int solve(vectornums){ - - int n = nums.size(); - - vector dp(n); - int i; - - if(n>=1) - dp[0] = nums[0]; - if(n>=2) - dp[1] = max(nums[0],nums[1]); - - for(i=2;i& nums) { - - int n = nums.size(); - - if(nums.size()==1) - return nums[0]; - - return max(solve(vector(nums.begin(),nums.end()-1)), solve(vector(nums.begin()+1,nums.end()))); - } -}; \ No newline at end of file diff --git a/longest_common_subsequence.cpp b/longest_common_subsequence.cpp deleted file mode 100644 index 333452d..0000000 --- a/longest_common_subsequence.cpp +++ /dev/null @@ -1,30 +0,0 @@ -class Solution { -public: - int longestCommonSubsequence(string text1, string text2) { - - int n = text1.size() , m = text2.size(); - int i,j; - - vector> dp(n+1, vector(m+1,0)); - - for(i=0;i<=n;i++) - dp[i][0] = 0; - - for(j=0;j<=m;j++) - dp[0][j] = 0; - - for(i=1;i<=n;i++){ - for(j=1;j<=m;j++){ - - if(text1[i-1] == text2[j-1]) - dp[i][j] = 1+ dp[i-1][j-1]; - - else - dp[i][j] = max(dp[i-1][j], dp[i][j-1]); - } - } - - return dp[n][m]; - } -}; -// \ No newline at end of file diff --git a/maximumSubarray.cpp b/maximumSubarray.cpp deleted file mode 100644 index c17ae7b..0000000 --- a/maximumSubarray.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - int maxSubArray(vector& nums) { - - int i, sum = 0, last = INT_MIN; - - - for(i=0;i palin; - int i=0; - while(x>0){ - int a = x%10; - - palin.push_back(a); - - x = x/10; - } - - int j = palin.size()-1; - - while(i& nums, int k) { - int i, temp; - - if(nums.size()!=0 && k>0){ - while(k--){ - temp = nums[nums.size()-1]; - - for(i=nums.size()-1;i>0;i--){ - nums[i] = nums[i-1]; - } - - nums[0] = temp; - } - } - } - // TLE issue - // time limit exceeded - -}; \ No newline at end of file