diff --git a/C++/100_Same_Tree.cpp b/C++/100_Same_Tree.cpp new file mode 100644 index 00000000..f9c4e19f --- /dev/null +++ b/C++/100_Same_Tree.cpp @@ -0,0 +1,27 @@ +/** + * 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 == nullptr && q == nullptr) + return true; + if(p == nullptr || q == nullptr) + return false; + if(p->val != q->val) return false; + + return (isSameTree(p->right,q->right) && isSameTree(p->left, q->left)); + } +}; + +// Complexity Analysis: +// Time complexity : O(N), where N is a number of nodes in the tree, since one visits each node exactly once. +// Space complexity :O(log(N)) in the best case of completely balanced tree and O(N) in the worst case of completely unbalanced tree. \ No newline at end of file diff --git a/C++/143.Reorder_List.cpp b/C++/143.Reorder_List.cpp new file mode 100644 index 00000000..b88c9c21 --- /dev/null +++ b/C++/143.Reorder_List.cpp @@ -0,0 +1,45 @@ +/* medium difficulty */ + +class Solution { +public: + void reorderList(ListNode* head) { + + //edge cases + if ((!head) || (!head->next) || (!head->next->next)) return; + + int l=0; //to calculate the length + ListNode* curr=head; + while(curr){ + l++; + curr=curr->next; + } + + //stack to store the second half of the elements of the ll + stack s; + curr=head; + + //iterating till the end of the first half + int m=(l+1)/2; + while(m>=1){ + curr=curr->next; + m--; + } + + //pushing the second half of the elements in the stack + while(curr){ + s.push(curr); + curr=curr->next; + } + + //attaching the elements from the top of the stack to the first half of the elements + curr=head; + while(curr&&!s.empty()){ + ListNode* temp=s.top(); + s.pop(); + temp->next=curr->next; + curr->next=temp; + curr=curr->next->next; + } + curr->next=NULL; + } +}; \ No newline at end of file diff --git a/C++/189.Rotate-array.cpp b/C++/189.Rotate-array.cpp new file mode 100644 index 00000000..faed77b3 --- /dev/null +++ b/C++/189.Rotate-array.cpp @@ -0,0 +1,32 @@ +difficulty level: Medium +class Solution { +public: + void rotate(vector& nums, int k) { + int n = nums.size(); + k = k % n; + // we first reverse all the elements,[7 6 5 4 3 2 1] + for (int i = 0, j = n - 1; i < j; i++, j--) { + swap(nums[i], nums[j]); + } + // then we reverse the set of elements sized k for example [7 6 5 4 3 2 1] = [ 5 6 7 4 3 2 1] + for (int i = 0, j = k - 1; i < j; i++, j--) { + swap(nums[i], nums[j]); + } + //finally we reverse the ending elements too = 5 6 7 1 2 3 4 + for (int i = k, j = n - 1; i < j; i++, j--) { + swap(nums[i], nums[j]); + } + } +}; + +Time complexity:O(n) +Space Complexity:O(1) +/* +Input: nums = [1,2,3,4,5,6,7], k = 3 +Output: [5,6,7,1,2,3,4] + +Example 2: + +Input: nums = [-1,-100,3,99], k = 2 +Output: [3,99,-1,-100] +*/ diff --git a/C++/238.Product_of_array_except_self b/C++/238.Product_of_array_except_self new file mode 100644 index 00000000..c09cff86 --- /dev/null +++ b/C++/238.Product_of_array_except_self @@ -0,0 +1,54 @@ +/* + This code uses prefix and postfix product to evaluate answer. + We just need to traverse the array twice, once to the left and once to the right. + Then answer of ith place can be calculated using constant time. + + Time Complexity : O(n) + Space Complexity : O(n) +*/ + + + +class Solution { +public: + vector productExceptSelf(vector& nums) { + int n = nums.size(); //Variable for size of the array + //pre[] stores product of all numbers to the left of ith element + //post[] stores product of all numbers to the right of ith element + int pre[n],post[n]; + + //loop to assign values to pre[] + int mul=1; + for(int i=0; i=0; i--){ + mul*=nums[i]; + post[i]=mul; + } + + //declare a vector to return + vector out; + + //first element of out is just going to be product of all elements except first one + out.push_back(post[1]); + + //value of out[i] = product of all elements except ith element + //which is nothing but pre[i-1]*[post[i+1]] + for(int i=1; i>&mp, TreeNode* root, int level) +{ + if(!root) + return; + + mp[level].push_back(root->val); + + fun(mp,root->left,level+1); + fun(mp,root->right,level+1); + +} + + vector> levelOrder(TreeNode* root) { + vector>v; + if(!root) + return v; + + map>mp; + int level=0; + fun(mp,root,level); + auto it=mp.begin(); + while(it!=mp.end()) + { + v.push_back(it->second); + it++; + } + + return v; + + } +}; diff --git a/C++/Daily_Temperatures.cpp b/C++/Daily_Temperatures.cpp new file mode 100644 index 00000000..3093df11 --- /dev/null +++ b/C++/Daily_Temperatures.cpp @@ -0,0 +1,46 @@ +/* +Given an array of integers temperatures represents the daily temperatures, +return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. +If there is no future day for which this is possible, keep answer[i] == 0 instead. + +Example 1: + +Input: temperatures = [73,74,75,71,69,72,76,73] +Output: [1,1,4,2,1,1,0,0] +Example 2: + +Input: temperatures = [30,40,50,60] +Output: [1,1,1,0] +Example 3: + +Input: temperatures = [30,60,90] +Output: [1,1,0] + +Constraints: + +1 <= temperatures.length <= 105 +30 <= temperatures[i] <= 100 +*/ + +/* +Space Complexity : O(N) +Time Complexity : O(NlogN) +Difficulty level : Medium +*/ +class Solution { +public: + vector dailyTemperatures(vector& temperatures) { + vector ans(temperatures.size()); + stack s; + + for(int i=0; i temperatures[s.top()]){ + const int k = s.top(); + s.pop(); + ans[k] = i - k; + } + s.push(i); + } + return ans; + } +}; diff --git a/C++/RedundantConnection.cpp b/C++/RedundantConnection.cpp new file mode 100644 index 00000000..e256c43b --- /dev/null +++ b/C++/RedundantConnection.cpp @@ -0,0 +1,46 @@ +/* +ProblemLink : https://leetcode.com/problems/redundant-connection/ + +In this problem, a tree is an undirected graph that is connected and has no cycles. + +You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. +The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed. +The graph is represented as an array edges of length n where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the graph. + +Return an edge that can be removed so that the resulting graph is a tree of n nodes. +If there are multiple answers, return the answer that occurs last in the input. +*/ + +class Solution { +public: + int find(int v,vector& parent){ + if(parent[v]==-1){ + return v; + } + return find(parent[v],parent); + } + void Union(int x,int y,vector& parent){ + parent[x]=y; + } + + vector findRedundantConnection(vector>& edges) { + int V = edges.size(); + vector parent(V+1,-1); + int v1,v2; + for(auto x:edges){ + int fromP = find(x[0],parent); + int toP = find(x[1],parent); + if(fromP==toP){ + v1=x[0]; + v2=x[1]; + } + else{ + Union(fromP,toP,parent); + } + } + vector ans; + ans.push_back(v1); + ans.push_back(v2); + return ans; + } +}; diff --git a/C++/Remove-Covered-Intervals.cpp b/C++/Remove-Covered-Intervals.cpp index 28de473f..52808d2d 100644 --- a/C++/Remove-Covered-Intervals.cpp +++ b/C++/Remove-Covered-Intervals.cpp @@ -27,3 +27,32 @@ class Solution { }; //Complexity: O(n*n) + + + +SIMPLIFIED SOLUTION in O(nlogn) time + +// +class Solution { +public: + int removeCoveredIntervals(vector>& intervals) { + sort(intervals.begin(),intervals.end(),[](vector& v1,vector& v2){ + if(v1[0]==v2[0]) + return v1[1]>v2[1]; + return v1[0]end) + { + end = intervals[i][1]; + sz++; + } + } + return sz; + } +}; + +// diff --git a/C++/Reshape-the-Matrix.cpp b/C++/Reshape-the-Matrix.cpp new file mode 100644 index 00000000..c1802c88 --- /dev/null +++ b/C++/Reshape-the-Matrix.cpp @@ -0,0 +1,23 @@ +class Solution { +public: + vector> matrixReshape(vector>& mat, int r, int c) { + if(mat.size()*mat[0].size() != r*c) return mat; + vector v; + for(int i=0;i> vnew; + vector input; + for(int i=0;i + +/*** 13. Roman to Intege (Easy)***/ + +/* +Symbol Value +I 1 +V 5 +X 10 +L 50 +C 100 +D 500 +M 1000 +*/ + +class Solution { +public: + int romanToInt(string s) { + int current = 0, last =0; + int sum=0; + for(int i=0;ilast) + sum-=2*last; + last = current; + + } + return sum; + } +}; \ No newline at end of file diff --git a/C++/Spiral-matrix.cpp b/C++/Spiral-matrix.cpp new file mode 100644 index 00000000..3625de6a --- /dev/null +++ b/C++/Spiral-matrix.cpp @@ -0,0 +1,37 @@ +//Problem Number : 54 +//Problem Name : Spiral Matrix +//Problem Statement : Given an m x n matrix, return all elements of the matrix in spiral order. + +class Solution { +public: + vector spiralOrder(vector>& matrix) { + vectorres; + int left = 0, top = 0, down = matrix.size()-1, right = matrix[0].size()-1; + + while(left <= right && top <= down){ + //From left to right on top side + for(int i = left; i <= right; i++) + res.push_back(matrix[top][i]); + top++; + //From top to down on right side + for(int i = top; i <= down; i++) + res.push_back(matrix[i][right]); + right--; + if(top <= down){ + //From right to left on down side + for(int i = right; i >= left; i--) + res.push_back(matrix[down][i]); + down--; + } + if(left <= right){ + //From down to top on left side + for(int i = down; i >= top; i--) + res.push_back(matrix[i][left]); + left++; + } + } + return res; + } +}; + +//This code is contributed by Nikhil-1503 diff --git a/C++/Swap-nodes-in-pairs.cpp b/C++/Swap-nodes-in-pairs.cpp new file mode 100644 index 00000000..05cb7ac4 --- /dev/null +++ b/C++/Swap-nodes-in-pairs.cpp @@ -0,0 +1,24 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution { +public: + ListNode* swapPairs(ListNode* head) { + if(head==NULL || head->next==NULL) + return head; + ListNode* p=head->next; + head->next=swapPairs(head->next->next); + p->next=head; + return p; + } +}; + +// Time Complexity: O(N) +// Space Complexity: O(1) diff --git a/C++/Valid_Parentheses.cpp b/C++/Valid_Parentheses.cpp new file mode 100644 index 00000000..0534dba2 --- /dev/null +++ b/C++/Valid_Parentheses.cpp @@ -0,0 +1,58 @@ +#include +#include +/* +Example 1: +Input: s = "()" +Output: true + +Example 2: +Input: s = "()[]{}" +Output: true + +Example 3: +Input: s = "(]" +Output: false + +Example 4: +Input: s = "([)]" +Output: false + +Example 5: +Input: s = "{[]}" +Output: true +*/ + +class Solution { +public: + bool isValid(string s) { + list open; + if(s.length()%2!=0) + return false; + for(int i=0; i>& wall) { + unordered_map widths; + auto result = wall.size(); + for (const auto& row : wall) { + for (auto i = 0, width = 0; i < row.size() - 1; ++i) { + result = min(result, wall.size() - (++widths[width += row[i]])); + } + } + return result; + } +}; \ No newline at end of file diff --git a/C++/container-with-most-water.cpp b/C++/container-with-most-water.cpp new file mode 100644 index 00000000..3db55daa --- /dev/null +++ b/C++/container-with-most-water.cpp @@ -0,0 +1,32 @@ +// https://leetcode.com/problems/container-with-most-water +// code for the question : "container-with-most-water" +// language : cpp + + +class Solution { + public: + int maxArea(vector& height) { + int n = height.size(); + int max_area = 0; // Variable to store the maximum water that can be contained + int i = 0; // Left pointer + int j = n - 1; // Right pointer + + // Use two-pointer approach to find the maximum area + while (i < j) { + // Calculate the area between the two current pointers + int current_area = (j - i) * min(height[i], height[j]); + + // Update the maximum area found so far + max_area = max(max_area, current_area); + + // Move the pointer with the smaller height + if (height[i] < height[j]) { + i++; // Move left pointer to the right + } else { + j--; // Move right pointer to the left + } + } + return max_area; + } + }; + \ No newline at end of file diff --git a/C++/letter-combinations-of-a-phone-number.cpp b/C++/letter-combinations-of-a-phone-number.cpp new file mode 100644 index 00000000..792a3476 --- /dev/null +++ b/C++/letter-combinations-of-a-phone-number.cpp @@ -0,0 +1,40 @@ +class Solution { +public: + unordered_map intToCharsMap; + + void backtracking(string::iterator lf,string::iterator rt,string &path,vector &result) + { + if(lf == rt) + { + result.push_back(path); + return; + } + for(auto c : intToCharsMap[*lf]) + { + path.push_back(c); + backtracking(next(lf,1),rt,path,result); + path.pop_back(); // if a character doesnot matches then we pop that character from the string and again backtrack. + } + } + vector letterCombinations(string digits) + { + int n = digits.size(); + if(digits == "") + return {}; + string path; + // result array stores every string that represents that digit. + vector result; + intToCharsMap = { + {'2', "abc"}, + {'3', "def"}, + {'4', "ghi"}, + {'5', "jkl"}, + {'6', "mno"}, + {'7', "pqrs"}, + {'8', "tuv"}, + {'9', "wxyz"}, + }; + backtracking(digits.begin(),digits.end(),path,result); + return result; + } +}; diff --git a/C++/number-of-islands.cpp b/C++/number-of-islands.cpp new file mode 100644 index 00000000..bffdc2c2 --- /dev/null +++ b/C++/number-of-islands.cpp @@ -0,0 +1,49 @@ +class Solution { +public: + bool visited[300][300]; + int r[4] = {-1,0,0,1}; + int c[4] = {0,-1,1,0}; + + //Checks if the given row and col value are valid and if the cell is visited and if the cell contains '1' or not. + bool val(int row,int col,vector>& grid,int M,int N) + { + return (row=0 && col>=0 && !visited[row][col] && grid[row][col]=='1'); + } + + //Dfs function for exploring the surrounding cells + void dfs(int i,int j,vector>& grid, int M, int N) + { + visited[i][j] = true; + for(int a=0;a<4;a++) + { + int row = i + r[a]; + int col = j + c[a]; + if(val(row,col,grid,M,N)) + { + dfs(row,col,grid,M,N); + } + } + } + + int numIslands(vector>& grid) { + int m = grid.size(); + int n = grid[0].size(); + memset(visited,0,sizeof(visited)); + int island_count = 0; + for(int i=0;i stack = new Stack(); + for (char c : s.toCharArray()) { + if (c == '(') + stack.push(')'); + else if (c == '{') + stack.push('}'); + else if (c == '[') + stack.push(']'); + else if (stack.isEmpty() || stack.pop() != c) + return false; + } + return stack.isEmpty(); +} diff --git a/Java/BrokenCalculator.java b/Java/BrokenCalculator.java new file mode 100644 index 00000000..4a119a05 --- /dev/null +++ b/Java/BrokenCalculator.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/broken-calculator/ + + public int brokenCalc(int startValue, int target) { + + + if(startValue >= target){ + return startValue - target; + } + + if(target % 2 == 0){ + return 1+brokenCalc(startValue,target/2); + } + + return 1+brokenCalc(startValue,target+1); + + } diff --git a/Java/FizzBuzz.java b/Java/FizzBuzz.java new file mode 100644 index 00000000..9034c2c0 --- /dev/null +++ b/Java/FizzBuzz.java @@ -0,0 +1,23 @@ + +import java.util.ArrayList; +import java.util.List; + +// https://leetcode.com/problems/fizz-buzz/ + + + public List fizzBuzz(int n) { + List s = new ArrayList<>(); + + for (int i = 1; i <= n ; i++) { + if( i % 15 == 0){ + s.add("FizzBuzz"); + }else if( i % 3 == 0){ + s.add("Fizz"); + }else if(i % 5 == 0){ + s.add("Buzz"); + }else{ + s.add(Integer.toString(i)); + } + } + return s; + } diff --git a/Java/June-LeetCoding-Challenge/Day22StrSubsequenceCount.java b/Java/June-LeetCoding-Challenge/Day22StrSubsequenceCount.java new file mode 100644 index 00000000..7db6fb78 --- /dev/null +++ b/Java/June-LeetCoding-Challenge/Day22StrSubsequenceCount.java @@ -0,0 +1,41 @@ +import java.util.*; + +public class Day22StrSubsequenceCount { + public static void main(String[] args){ + String str = "abacde"; + String[] words = {"a", "bb", "acd", "ace"}; + int count = numMatchingSequence(str,words); + System.out.println(count); + } + + public static int numMatchingSequence(String str, String[] words){ + int result = 0; + Map> map = new HashMap<>(); + + for(int i=0; i()); + map.get(str.charAt(i)).add(i); // It will add size of that character in map (occurence) + } + + for (String word : words) { + if (match(str, word, map, 0)) { + result++; + } + } + + return result; + } + + private static boolean match(String S, String word, Map> map, int startIndex) { + if (word.length() == 0) return true; + if (!map.containsKey(word.charAt(0))) return false; + for (int start : map.get(word.charAt(0))) { + if (start < startIndex) continue; + String newWord = word.substring(1, word.length()); + return match(S, newWord, map, start + 1); + } + + return false; + } + +} diff --git a/Java/June-LeetCoding-Challenge/StringOperationsCount.java b/Java/June-LeetCoding-Challenge/StringOperationsCount.java new file mode 100644 index 00000000..8561d6b0 --- /dev/null +++ b/Java/June-LeetCoding-Challenge/StringOperationsCount.java @@ -0,0 +1,54 @@ +public class StringOperationsCount { + public static void main(String[] args) { + // NOTE: The following input values will be used for testing your solution. + // Should return true if inserting a single char, deleting it or replacing it. + System.out.println(isOneAway("abcde", "abcd")); // should return true + System.out.println(isOneAway("abde", "abcde")); // should return true + System.out.println(isOneAway("a", "a")); // should return + System.out.println(isOneAway("a", "b")); // should return true + System.out.println(isOneAway("abcdef", "abqdef")); // should return true + System.out.println(isOneAway("abcdef", "abccef")); // should return true + System.out.println(isOneAway("abcdef", "abcde")); // should return true + System.out.println(isOneAway("aaa", "abc")); // should return false beacuse its two character replace + System.out.println(isOneAway("abcde", "abc")); // should return false + System.out.println(isOneAway("abc", "abcde")); // should return false + System.out.println(isOneAway("abc", "bcc")); // should return false + } + + // Implement your solution below. + public static Boolean isOneAway(String s1, String s2) { + boolean bool = false; + int s1Length = s1.length(); + int s2Length = s2.length(); + int editDistance = getEditDistance(s1, s2,s1Length,s2Length); + if(editDistance>1) + return false; + else + return true; + } + + private static int getEditDistance(String s1, String s2,int s1Length, int s2Length) { + + if(s1Length==0){ + return s2Length; + } + if(s2Length==0){ + return s1Length; + } + if(s1.charAt(s1Length-1)== s2.charAt(s2Length-1)) + return getEditDistance(s1,s2,s1Length-1,s2Length-1); + + return 1+ min(getEditDistance(s1,s2,s1Length,s2Length-1) + ,getEditDistance(s1,s2,s1Length-1,s2Length), + getEditDistance(s1,s2,s1Length-1,s2Length-1)); + } + + private static int min(int x, int y, int z) { + if (x <= y && x <= z) + return x; + if (y <= x && y <= z) + return y; + else + return z; + } +} diff --git a/Java/PascalsTriangle118.java b/Java/PascalsTriangle118.java new file mode 100644 index 00000000..b8e706cb --- /dev/null +++ b/Java/PascalsTriangle118.java @@ -0,0 +1,29 @@ +import java.util.ArrayList; +import java.util.List; + +class Solution { + public List> generate(int numRows) { + + List> triangle = new ArrayList<>(); + + if(numRows ==0) return triangle; + + List first_row = new ArrayList<>(); + first_row.add(1); + triangle.add(first_row); + + for(int i=1; i prev_row = triangle.get(i-1); + List row = new ArrayList<>(); + row.add(1); + + for(int j=1; j O(1) constant as 32 is the number of bits at most we will have to bit shift until carry is zero. +// Space-Complexity:- O(1) + + +class Solution { + public int getSum(int a, int b) { + + int xor=a ^ b; + int carry= a & b; + if(carry == 0) + return xor; + else + return getSum(xor,carry<<1); + } +} diff --git a/Java/WaterBottles.java b/Java/WaterBottles.java new file mode 100644 index 00000000..6e0a9cc0 --- /dev/null +++ b/Java/WaterBottles.java @@ -0,0 +1,17 @@ + + +// https://leetcode.com/problems/water-bottles/ + + + public int numWaterBottles(int numBottles, int numExchange) { + + int total = numBottles; + while(numBottles>=numExchange) + { + int exchange=numBottles/numExchange; + int rem=numBottles%numExchange; + total+=exchange; + numBottles=exchange+rem; + } + return total; + } diff --git a/Java/evaluate_reverse_polish_notation.java b/Java/evaluate_reverse_polish_notation.java new file mode 100644 index 00000000..feaae56a --- /dev/null +++ b/Java/evaluate_reverse_polish_notation.java @@ -0,0 +1,30 @@ + + +class Solution { + public int evalRPN(String[] tokens) { + Stack st = new Stack<>(); + int a,b; + for(String s: tokens){ + if(s.equals("+")){ + st.add(st.pop()+st.pop()); + } + else if(s.equals("*")){ + st.add(st.pop() * st.pop()); + } + else if(s.equals("/")){ + b=st.pop(); + a = st.pop(); + st.add(a/b); + } + else if(s.equals("-")){ + b = st.pop(); + a = st.pop(); + st.add(a-b); + } + else{ + st.add(Integer.parseInt(s)); + } + } + return st.pop(); + } +} diff --git a/Java/string-to-integer-atoi.java b/Java/string-to-integer-atoi.java new file mode 100644 index 00000000..7c7cbcdc --- /dev/null +++ b/Java/string-to-integer-atoi.java @@ -0,0 +1,65 @@ +package com.bst.myexamples; + +/** + * Solution accepted on Leetcode with 7ms runtime and 39.2MB memory + * + * String to Integer (atoi) + * Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function). + * Approach + * 1.Prepare String that is having only +- sign and number value + * Convert to BigInteger to compare value with 32bit signed Integer range and clamp if goes out of range + * return output with 0 if no string number found or non number value found before any number value + */ + +import java.math.*; +class StringToIntegerATOI { + + public static void main(String[] args){ + /* StringToIntegerATOI sta = new StringToIntegerATOI(); + System.out.println(sta.myAtoi("-20000000000000")); +*/ + + } + public int myAtoi(String s) { + + StringBuilder sb = new StringBuilder(); + + for(int i=0; i 0) + lvar = BigInteger.valueOf(Integer.MAX_VALUE); + else if(lvar.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0) + lvar = BigInteger.valueOf(Integer.MIN_VALUE); + + return lvar.intValue(); + } +} \ No newline at end of file diff --git a/JavaScript/findPeakElement.js b/JavaScript/findPeakElement.js new file mode 100644 index 00000000..0247691b --- /dev/null +++ b/JavaScript/findPeakElement.js @@ -0,0 +1,31 @@ +/** + * Given an 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. + +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. + + */ + +/** + * @param {number[]} nums + * @return {number} + */ +var findPeakElement = function (nums) { + let left = 0, + right = nums.length - 1, + mid; + + while (left < right) { + mid = Math.floor((right + left) / 2); + if (nums[mid] > nums[mid + 1]) right = mid; + else left = mid + 1; + } + return left; +}; diff --git a/JavaScript/single-number.js b/JavaScript/single-number.js new file mode 100644 index 00000000..8096e79e --- /dev/null +++ b/JavaScript/single-number.js @@ -0,0 +1,52 @@ +/** + * Given a non-empty array of integers, every element appears twice except for + * one. Find that single one. + * + * Note: + * + * Your algorithm should have a linear runtime complexity. Could you implement + * it without using extra memory? + * + * Example 1: + * + * Input: [2,2,1] Output: 1 + * + * Example 2: + * + * Input: [4,1,2,1,2] Output: 4 + * + */ + +/** + * @param {number[]} nums + * @return {number} + */ +var singleNumber = function(nums) { + result= [] + nums.sort() + + nums.forEach(element => { + if (result.indexOf(element) == -1){ + result.push(element) + }else{ + result.splice(result.indexOf(element),1) + } + }); + + return result[0] +}; + + + +//------- Test cases ----------------- +// Input: nums = [2,2,1] +// Output: 1 +console.log(`Example 01 = ${singleNumber([2,2,1])} expected Output 1.`) + +// Input: nums = [4,1,2,1,2] +// Output: 4 +console.log(`Example 02 = ${singleNumber([4,1,2,1,2])} expected Output 4.`) + +// Input: nums = [1] +// Output: 1 +console.log(`Example 03 = ${singleNumber([1])} expected Output 1.`) diff --git a/Python/Longest_Substring_Without_Repeating_Characters.py b/Python/Longest_Substring_Without_Repeating_Characters.py new file mode 100644 index 00000000..bd3a011a --- /dev/null +++ b/Python/Longest_Substring_Without_Repeating_Characters.py @@ -0,0 +1,29 @@ +""" +LeetCode submission result: + (987 / 987 test cases passed. \ Status: Accepted \ Runtime: 76 ms \ Memory Usage: 14.4 MB) + - available at: https://leetcode.com/submissions/detail/531509506/ +""" + +class Solution: + def lengthOfLongestSubstring(self, string: str) -> int: + + # Creating a charactersCountDict to store count of characters in the current + charactersCountDict = {} + + # declaring variables to mark the Starting Index as well as Maximum Length of any contiguous substring without recurring characters achieved + currentStartingIndex = maxLength = 0 + + # Iterating through all indices of the string, one by one, while analyzing string between 'currentStartingIndex' and this ending 'index'. + for index in range(len(string)): + # In case string character at this index already exists between string[currentStartingIndex:index], then removing the starting of string from currentStartingIndex considered to remove any repeated characters in the considered string + while string[index] in charactersCountDict: + charactersCountDict[string[currentStartingIndex]] -= 1 # Reducing the string character count of string[currentStartingIndex] character so as to eliminate it from current string (in the considered sliding window) + if charactersCountDict[string[currentStartingIndex]] < 1: charactersCountDict.pop(string[currentStartingIndex]) # If current count of this character goes below 1, that means this character no longer exists in the substring, therefore the character key is removed from charactersCountDict counter dictionary + currentStartingIndex += 1 # Shifting the currentStartingIndex one step ahead + + # Now that the while loop has completed, it is assured that this character is not included in the substring string[currentStartingIndex:index], therefore we can safely insert it in string[currentStartingIndex:index+1] (last index excluded in the string slice) + charactersCountDict[string[index]] = 1 + + maxLength = max(maxLength, index-currentStartingIndex+1) # Assessing maxLength to be maximum of current substring with unique character and maximum length achieved at any point of time while carefully sliding the limits + + return maxLength # Finally, returning the desired maximum length of contiguous substring that has no repeating characters diff --git a/Python/baseK.py b/Python/baseK.py new file mode 100644 index 00000000..45de79cc --- /dev/null +++ b/Python/baseK.py @@ -0,0 +1,17 @@ +def sumBase(n: int, k: int) : + """ +Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k. +After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10. +TC : O(N) +SC : O(1) +n : int (integer base 10) +k : int (base to be converted to) +return value : int +""" + summation=0 + while n >= k : + + summation = summation + n%k + n=n//k + print(n) + return (summation + n) \ No newline at end of file diff --git a/Python/jumpGame.py b/Python/jumpGame.py new file mode 100644 index 00000000..a522c3cd --- /dev/null +++ b/Python/jumpGame.py @@ -0,0 +1,34 @@ +# 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. + +# 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. + +# 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. + +''' + Time Complexity: O(n), + Space Complexity: O(n) +''' + +def canJump(nums): + ptr1 = len(nums) - 1 + ptr2 = ptr1 - 1 + + while ptr2 >= 0: + if nums[ptr2] >= ptr1 - ptr2: + ptr1 = ptr2 + ptr2 -= 1 + else : + ptr2 -= 1 + + if ptr1 == 0: + return True + else: + return False + +print(canJump[3,2,1,0,4]) \ No newline at end of file diff --git a/README.md b/README.md index bf89f49f..85accc7c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ # [LeetCode-Solutions](https://www.youtube.com/playlist?list=PLlUdLC2oSxz2Y1g6V8oRCzauOvbnKl2Ee)

- - - - - +

Join Us on Telegram & Facebook

+ + + + + - +

@@ -16,7 +17,7 @@ Forks Badge GitHub contributors -[![GitHub issues by-label](https://img.shields.io/github/issues-pr-closed-raw/codedecks-in/LeetCode-Solutions.svg)](https://github.com/codedecks-in/LeetCode-Solutions/pulls?q=is%3Apr+is%3Aclosed) + @@ -33,7 +34,8 @@ Issues Badge --> -### Got stuck in a LeetCode question? This repository will help you by providing approach of solving the problems from LeetCode platform. +### Got stuck in a LeetCode question? +### This repository will help you by providing approach of solving the problems from LeetCode platform. ### [Contributors](#contributors) helped us in providing these Awesome solutions. @@ -82,12 +84,13 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | | ---- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | -| 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java)
[Python](./Python/single-number.py)
[C++](./C++/Single-Number.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR | -| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py)
[C++](./C++/Single-Number-II.cpp) | _O(n)_ | _O(1)_ | Medium | | | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py)
[C++](./C++/Single-Number-III.cpp) | _O(n)_ | _O(1)_ | Medium | | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java)
[C++](./C++/Number-Complement.cpp) | _O(1)_ | _O(1)_ | Easy | | [Tutorial](https://youtu.be/6bp5V-O3zts) | -| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py)
[C++](./C++/Detect-Capital.cpp) | _O(n)_ | _O(1)_ | Easy | | | -| 1486 | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) | [Java](./Java/xor-op-in-array.java) | _O(n)_ | _O(1)_ | Easy | | Using XOR | +| 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java)
[Python](./Python/single-number.py)
[C++](./C++/Single-Number.cpp)
[JavaScript](./JavaScript/single-number.js) | _O(n)_ | _O(1)_ | Easy | | Using XOR | +| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py)
[C++](./C++/Single-Number-II.cpp) | _O(n)_ | _O(1)_ | Medium | | | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py)
[C++](./C++/Single-Number-III.cpp) | _O(n)_ | _O(1)_ | Medium | | | +| 371 | [Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/) | [Java](./Java/Sum_of_two_integers.java) | _O(1)_ | _O(1)_ | Medium | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java)
[C++](./C++/Number-Complement.cpp) | _O(1)_ | _O(1)_ | Easy | | [Tutorial](https://youtu.be/6bp5V-O3zts) | +| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py)
[C++](./C++/Detect-Capital.cpp) | _O(n)_ | _O(1)_ | Easy | | | +| 1486 | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) | [Java](./Java/xor-op-in-array.java)
[C++](./C++/xor-operation-in-an-array.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR |

@@ -97,9 +100,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Sort -| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | -| ---- | --------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | -| 973 | [K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin/) | [C++](./C++/k-closest-points-to-origin.cpp) | _O(n)_ | _O(1)_ | Medium | | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | +| --- | --------------------------------------------------------------------------------------- | ------------------------------------------- | ------ | ------ | ---------- | --- | -------- | +| 973 | [K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin/) | [C++](./C++/k-closest-points-to-origin.cpp) | _O(n)_ | _O(1)_ | Medium | | |
@@ -111,6 +114,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Note | Video Explaination | | ------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------ | ------------- | ---------- | ------------------ | ---------------------------------------- | +| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/) | [Java](./Java/PascalsTriangle118.java) | _O(N^2)_ | _O(N)_ | Easy | | | | 56 | [Merge Intervals](https://leetcode.com/problems/merge-intervals) | [Python](./Python/56_MergeIntervals.py) | _O(nlogn)_ | _O(n)_ | Medium | Intervals | | | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [Java](./Java/missing-number.java) | _O(n)_ | _O(1)_ | Easy | Array | [Tutorial](https://youtu.be/VwvGEE_OGss) | | 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | [Java](./Java/Degree-of-an-Array.java) | _O(n)_ | _O(n)_ | Easy | Array | | @@ -120,7 +124,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [Python](./Python/pascals-triangle-ii.py) | _O(N^2)_ | _O(K)_ | Easy | | | | 1480 | [Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/) | [Java](./Java/running-sum-of-1d-array.java) | _O(N)_ | _O(N)_ | Easy | Simple sum | | | 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/) | [Python](./Python/trapping_rain.py) | _O(N^2)_ | _O(N)_ | Hard | Array | | -| 11 | [Container with Most Water](https://leetcode.com/problems/container-with-most-water/) | [Python](./Python/container_with_most_water.py) | _O(N)_ | _O(N)_ | Medium | Array Two Pointers | | +| 11 | [Container with Most Water](https://leetcode.com/problems/container-with-most-water/) | [Python](./Python/container_with_most_water.py)
[C++](./C++/container-with-most-water.cpp) | _O(N)_ | _O(N)_ | Medium | Array Two Pointers | | | 1134 🔒 | [Armstrong Number](https://leetcode.com/problems/armstrong-number/) | [Java](./Java/Armstrong-Number.java) | _O(N)_ | _O(1)_ | Easy | | | | 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets/) | [Python](./Python/count-good-triplets.py) | _O(N^3)_ | _O(1)_ | Easy | | | | 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/) | [Java](./Java/matrix-diagonal-sum.java) | _O(N)_ | _O(1)_ | Easy | | | @@ -136,12 +140,18 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 189 | [Rotate-Array](https://leetcode.com/problems/rotate-array/) | [Python](./Python/rotate-array.py) | O(N) | O(1) | Medium | Array | | 496 | [next-greater-element-i](https://leetcode.com/problems/next-greater-element-i) | [Python](./Python/496_nextgreaterelement.py) | O(N) | O(1) | Medium | Array | | 1470 | [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array) | [Java](./Java/shuffle-the-array.java) | O(N) | O(1) | Easy | Array | -| 124 | [Permutation by Recussion](https://leetcode.com/problems/permutations/) | [Java](./Java/shuffle-the-array.java) | O(N) | O(N) | Easy | Array | +| 124 | [Permutation by Recussion](https://leetcode.com/problems/permutations/) | [Java](./Java/shuffle-the-array.java) | O(N) | O(N) | Easy | Array | | 283 | [Move-Zeroes](https://leetcode.com/problems/move-zeroes/) | [C++](./C++/Move-Zeroes.cpp) | O(N) | O(1) | Easy | Array | -| 27 | [Remove-Element](https://leetcode.com/problems/remove-element/) | [C++](./C++/remove-element.cpp) | O(N) | O(1) | Easy | Array | -| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku/) | [Java](./Java/valid-sudoku.java) | O(N^2) | O(N) | Medium | Array, 2D Matrix | -| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/) | [Java](./Java/Number-of-Good-Pairs.java) | O(N^2) | O(1) | Easy | Array | +| 27 | [Remove-Element](https://leetcode.com/problems/remove-element/) | [C++](./C++/remove-element.cpp) | O(N) | O(1) | Easy | Array | +| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku/) | [Java](./Java/valid-sudoku.java) | O(N^2) | O(N) | Medium | Array, 2D Matrix | +| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/) | [Java](./Java/Number-of-Good-Pairs.java) | O(N^2) | O(1) | Easy | Array | +| 162 | [Find Peak element](https://leetcode.com/problems/find-peak-element/) | [javascript](https://github.com/codedecks-in/LeetCode-Solutions/blob/master/JavaScript/findPeakElement.js) | o(Logn) | O(1) | Medium | Array | +| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) | [C++](./C++/Spiral-matrix.cpp) | O(M\*N) | O(M\*N) | Medium | Array | +| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) | [C++](./C++/238.Product_of_array_except_self) | O(N) | O(N) | Medium | Array | + +
+ @@ -150,17 +160,19 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # String | # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------------- | +| :--: | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------------- | +| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [Python](./Python/Longest_Substring_Without_Repeating_Characters.py) | _O(n)_ | _O(n)_ | Medium | `Hash Table`
`Sliding Window` | Open for improvisation, mentioned time and space complexities unconfirmed | +| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/) | [Java](./Java/string-to-integer-atoi.java) | _O(n)_ | _O(1)_ | Medium | | | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | | +| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/) | [Java](./Java/reverse-words-in-a-string.java) | _O(1)_ | _O(n)_ | Medium | | | | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note/) | [Java](./Java/ransom-note.java) | _O(1)_ | _O(n)_ | Easy | | Character Count | | 387 | [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/) | [Java](./Java/first-unique-character-in-a-string.java) | _O(n)_ | _O(1)_ | Easy | | Character Count | -| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/) | [Java](./Java/reverse-words-in-a-string.java) | _O(1)_ | _O(n)_ | Medium | | | | 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Java](./Java/detect-capital-use.java) | _O(n)_ | _O(1)_ | Easy | | | +| 767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./Python/reorganize-string.py) | _O(n)_ | _O(n)_ | Medium | | | +| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | | | 1221 | [Split a String in Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings/) | [Python](./Python/split-a-string-in-balanced-strings.py) | _O(n)_ | _O(1)_ | Easy | | | -| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Java](./Java/max-nesting-depth-parentheses.java) | _O(n)_ | _O(1)_ | Easy | | | | 1374 | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | [Java](./Java/generate-a-string-with-characters-that-have-odd-counts.java) | _O(n)_ | _O(1)_ | Easy | | | -| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | | -| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | | -| 767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./Python/reorganize-string.py) | _O(n)_ | _O(n)_ | Medium | | | +| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Java](./Java/max-nesting-depth-parentheses.java) | _O(n)_ | _O(1)_ | Easy | | |
⬆️ Back to Top @@ -169,18 +181,20 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Linked List -| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | -| --- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ---------- | ------ | ---------- | ------------------ | ---- | -| 002 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [Java](./Java/Add-Two-Numbers.java) | _O(n)_ | _O(n)_ | Medium | Math | | -| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) | [Java](./Java/remove-nth-node-from-end-of-list.java) | _O(n)_ | _O(1)_ | Medium | Two pointers | | -| 23 | [Merge K sorted lists](https://leetcode.com/problems/merge-k-sorted-lists/) | [C++](./C++/merge-k-sorted-lists.cpp) | _O(nlogn)_ | _O(n)_ | Hard | sorting and append | | -| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/) | [Java](./Java/convert-sorted-list-to-binary-search-tree.java) | _O(n)_ | _O(n)_ | Medium | LinkedList | | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/) | [Java](./Java/linked-list-cycle.java) | _O(n)_ | _O(1)_ | Easy | Slow-Fast Pointers | | -| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/) | [Java](./Java/linked-list-cycle-ii.java)
[C++](./C++/Linked-List-Cycle-II.cpp) | _O(n)_ | _O(1)_ | Medium | Slow-Fast Pointers | | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [C++](./C++/LRU-Cache.cpp)
[Python](./Python/LRUCache.py) | _O(1)_ | _O(k)_ | Medium | Hash Map | | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists/) | [Java](./Java/intersection-of-two-linked-lists.java) | _O(n)_ | _O(1)_ | Easy | Two Pointers | [Tutorial](https://youtu.be/uozGB0-gbvI) | -| 186 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/) | [Java](./Java/middle-of-the-linked-list.java) | _O(n)_ | _O(1)_ | Easy | Two pointers | | - +| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | +| --- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ---------- | ------ | ---------- | ------------------ | ---------------------------------------- | +| 002 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [Java](./Java/Add-Two-Numbers.java) | _O(n)_ | _O(n)_ | Medium | Math | | +| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) | [Java](./Java/remove-nth-node-from-end-of-list.java) | _O(n)_ | _O(1)_ | Medium | Two pointers | | +| 23 | [Merge K sorted lists](https://leetcode.com/problems/merge-k-sorted-lists/) | [C++](./C++/merge-k-sorted-lists.cpp) | _O(nlogn)_ | _O(n)_ | Hard | sorting and append | | +| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/) | [Java](./Java/convert-sorted-list-to-binary-search-tree.java) | _O(n)_ | _O(n)_ | Medium | LinkedList | | +| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/) | [Java](./Java/linked-list-cycle.java) | _O(n)_ | _O(1)_ | Easy | Slow-Fast Pointers | | +| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/) | [Java](./Java/linked-list-cycle-ii.java)
[C++](./C++/Linked-List-Cycle-II.cpp) | _O(n)_ | _O(1)_ | Medium | Slow-Fast Pointers | | +| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [C++](./C++/LRU-Cache.cpp)
[Python](./Python/LRUCache.py) | _O(1)_ | _O(k)_ | Medium | Hash Map | | +| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists/) | [Java](./Java/intersection-of-two-linked-lists.java) | _O(n)_ | _O(1)_ | Easy | Two Pointers | [Tutorial](https://youtu.be/uozGB0-gbvI) | +| 186 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/) | [Java](./Java/middle-of-the-linked-list.java) | _O(n)_ | _O(1)_ | Easy | Two pointers | +| 143 | [Reorder List](https://leetcode.com/problems/reorder-list/) | [C++](./C++/143.Reorder_List.cpp) | _O(n)_ | _O(n)_ | Medium | Iteration and Stack | +| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | [C++](./C++/Swap-nodes-in-pairs.cpp) | _O(n)_ | _O(1)_ | Medium | Two pointers | +
@@ -192,9 +206,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Note | | ---- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ------ | ------ | ---------- | ---------------------- | ---- | -| 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) | _O(n)_ | _O(n)_ | Easy | Stack | | +| 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) [C++](./C++/Vlalid_Parentheses.cpp)[Java](./Java/20.ValidParentheses.java) | _O(n)_ | _O(n)_ | Easy | Stack | | | 084 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | [C++](./C++/Largest-Rectangle-in-Histogram.cpp) | _O(n)_ | _O(n)_ | Hard | Stack | -| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) | _O(n)_ | _O(1)_ | Medium | Stack | | +| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py)
[Java](./Java/evaluate_reverse_polish_notation.java) | _O(n)_ | _O(1)_ | Medium | Stack | | | 1047 | [Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) | [C++](./C++/remove-all-adjacent-duplicates-in-string.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | | | 682 | [Baseball Game](https://leetcode.com/problems/baseball-game/) | [C++](./C++/Baseball-Game.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | | | 1381 | [Design a Stack With Increment Operation](https://leetcode.com/problems/design-a-stack-with-increment-operation/) | [Java](./Java/Design-a-Stack-With-Increment-Operation.java) | _O(n)_ | _O(n)_ | Medium | Stack | | @@ -202,9 +216,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Python](./Python/binary-tree-inorder-traversal.py) | _O(n)_ | _O(n)_ | Medium | Recursion, Binary Tree | | 735 | [Asteroid Collision](https://leetcode.com/problems/asteroid-collision/) | [C++](./C++/asteroid-collision.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | | 394 | [Decode String](https://leetcode.com/problems/decode-string/) | [C++](./C++/decode-string.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | -| 921 | [Minimum Add to Make Parentheses Valid](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) | [C++](./C++/minimum-add-to-make-parentheses-valid.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | -| 32 | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses/) | [Python](.Python/longest-valid-parentheses.py) | _O(n)_ | _O(n)_ | Hard | Stack | | -| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/) | [C++](./C++/minimum-remove-to-make-valid-parentheses.cpp) | _O(n)_ | _O(n)_ | Medium | Stack | | +| 921 | [Minimum Add to Make Parentheses Valid](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) | [C++](./C++/minimum-add-to-make-parentheses-valid.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | +| 32 | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses/) | [Python](.Python/longest-valid-parentheses.py) | _O(n)_ | _O(n)_ | Hard | Stack | | +| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/) | [C++](./C++/minimum-remove-to-make-valid-parentheses.cpp) | _O(n)_ | _O(n)_ | Medium | Stack | | +
⬆️ Back to Top @@ -243,7 +258,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 1028 | [Recover a Tree From Preorder Traversal](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/) | [C++](./C++/Recover-a-Tree-From-Preorder-Traversal.cpp) | _O(n)_ | _O(n)_ | Hard | Tree | | | 968 | [Binary Tree Cameras](https://leetcode.com/problems/binary-tree-cameras/) | [C++](./C++/Binary-Tree-Cameras.cpp) | _O(n)_ | _O(logn)_ | Hard | Binary Tree, Dynamic Programming | | 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/) | [Javascript](./JavaScript/98.Validate-Binary-Search-Tree.js) | _O(log(n))_ | _O(log(n))_ | Medium | Binary Tree | -| 684 | [Redundant Connection](https://leetcode.com/problems/redundant-connection/) | [Java](./Java/Redundant-Connection/redundant-connection.java) | _O(N)_ | _O(N)_ | Medium | Tree, Union Find | +| 684 | [Redundant Connection](https://leetcode.com/problems/redundant-connection/) | [Java](./Java/Redundant-Connection/redundant-connection.java) | _O(N)_ | _O(N)_ | Medium | Tree, Union Find | +| 102 | [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/) |[C++](./C++/Binary-Tree-Level-Order-Traversal.cpp)| _O(n)_ | _O(n)_ | Medium | Binary Tree, map | |
@@ -253,17 +269,17 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Hash Table -| # | Title | Solution | Time | Space | Difficulty | Tag | Video Explanation | -| --- | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ----------- | ------ | ---------- | --- | ------------------------------------------------------- | -| 001 | [Two Sum](https://leetcode.com/problems/two-sum/) | [Java](./Java/two-sum.java)
[Python](./Python/1_TwoSum.py)
[C++](./C++/two-sum.cpp) | _O(N)_ | _O(N)_ | Easy | | [Tutorial](https://youtu.be/47xMuvwP7zQ) | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [Java](./Java/valid-anagram.java) | _O(n)_ | _O(1)_ | Easy | | [Tutorial](https://www.youtube.com/watch?v=sbX1Ze9lNQE) | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Java](./Java/LRU-Cache.java) | | | Medium | | | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | [Python](./Python/contains-duplicate.py) | _O(n)_ | _O(n)_ | | | -| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | -| 049 | [Group Anagrams](https://leetcode.com/problems/group-anagrams/) | [Python](./Python/group_anagram.py) | _O(nlogn)_ | _O(1)_ | Easy | | -| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Javascript](../JavaScript/146.LRU-Cache.js) | _O(log(n))_ | _O(n)_ | Medium | | -| 389 | [Find The Difference](https://leetcode.com/problems/find-the-difference/) | [C++](../C++/Find-The-Difference.cpp) | _O(n)_ | _O(1)_ | Easy | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Video Explanation | +| --- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ----------- | ------ | ---------- | --- | ------------------------------------------------------- | +| 001 | [Two Sum](https://leetcode.com/problems/two-sum/) | [Java](./Java/two-sum.java)
[Python](./Python/1_TwoSum.py)
[C++](./C++/two-sum.cpp) | _O(N)_ | _O(N)_ | Easy | | [Tutorial](https://youtu.be/47xMuvwP7zQ) | +| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [Java](./Java/valid-anagram.java) | _O(n)_ | _O(1)_ | Easy | | [Tutorial](https://www.youtube.com/watch?v=sbX1Ze9lNQE) | +| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Java](./Java/LRU-Cache.java) | | | Medium | | | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | [Python](./Python/contains-duplicate.py) | _O(n)_ | _O(n)_ | | | +| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | +| 049 | [Group Anagrams](https://leetcode.com/problems/group-anagrams/) | [Python](./Python/group_anagram.py) | _O(nlogn)_ | _O(1)_ | Easy | | +| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | +| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Javascript](../JavaScript/146.LRU-Cache.js) | _O(log(n))_ | _O(n)_ | Medium | | +| 389 | [Find The Difference](https://leetcode.com/problems/find-the-difference/) | [C++](../C++/Find-The-Difference.cpp) | _O(n)_ | _O(1)_ | Easy | |
@@ -279,7 +295,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 4 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [Java](./Java/median-of-two-sorted-arrays.java) | _O(log(min(m,n)))_ | _O(1)_ | Hard | | | | 845 | [Longest Mountain in Array](https://leetcode.com/problems/longest-mountain-in-array/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | 015 | [3 Sum](https://leetcode.com/problems/3sum/) | [C++](./C++/3sum.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | -| 021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Easy | Two Pointer | | +| 021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Easy | Two Pointer | |
@@ -290,21 +306,24 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Math -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| --- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ----------------- | ------ | ---------- | ------ | ---- | -| 050 | [Pow(x, n)](https://leetcode.com/problems/powx-n/) | [Python](./Python/50.Powxn.py)
[JavaScript](./JavaScript/50.Powxn.js) | _O(n)_ | _O(1)_ | Medium | Math | | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [C++](./C++/Count-Primes.cpp) | _O(n(log(logn)))_ | _O(n)_ | Easy | Math | | -| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/) | [C++](./C++/Excel-Sheet-Column-Number.cpp) | _O(n)_ | _O(1)_ | Easy | String | | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [C++](./C++/Excel-Sheet-Column-Title.cpp) | _O(n)_ | _O(n)_ | Easy | String | | -| 007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](./Java/reverse-integer.java)
[C++](./C++/Reverse-Integer.cpp) | _O(n)_ | _O(n)_ | Easy | Math | | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | -| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | -| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | | -| 14 | [Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/) | [Java](./Java/Arithmetic-Subarrays.java) | _O(m*n)_ | _O(n)_ | Medium | Math | Pattern Count | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number/) | [Java](./Java/Ugly-Number.java) | _O(n)_ | _O(n)_ | Easy | Math | | - - +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| --- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ----------------- | ------ | ---------- | ------ | ------------- | +| 050 | [Pow(x, n)](https://leetcode.com/problems/powx-n/) | [Python](./Python/50.Powxn.py)
[JavaScript](./JavaScript/50.Powxn.js) | _O(n)_ | _O(1)_ | Medium | Math | | +| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [C++](./C++/Count-Primes.cpp) | _O(n(log(logn)))_ | _O(n)_ | Easy | Math | | +| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/) | [C++](./C++/Excel-Sheet-Column-Number.cpp) | _O(n)_ | _O(1)_ | Easy | String | | +| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [C++](./C++/Excel-Sheet-Column-Title.cpp) | _O(n)_ | _O(n)_ | Easy | String | | +| 007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](./Java/reverse-integer.java)
[C++](./C++/Reverse-Integer.cpp) | _O(n)_ | _O(n)_ | Easy | Math | | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | +| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java)
[C++](./C++/Roman_to_Integer.cpp)| _O(n)_ | _O(1)_ | Easy | Math | | +| 14 | [Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/) | [Java](./Java/Arithmetic-Subarrays.java) | _O(m\*n)_ | _O(n)_ | Medium | Math | Pattern Count | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number/) | [Java](./Java/Ugly-Number.java) | _O(n)_ | _O(n)_ | Easy | Math | | +| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz/) | [Java](./Java/FizzBuzz.java) | _O(n)_ | _O(n)_ | Easy | Math | | +| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles/) | [Java](./Java/WaterBottles.java) | _O(n)_ | _O(n)_ | Easy | Math | | +| 1822 | [Sign Of Product](https://leetcode.com/problems/sign-of-the-product-of-an-array/) | [Java](./Java/SignOf.java) | _O(n)_ | _O(n)_ | Easy | Math | | +| 991 | [Broken Calculator](https://leetcode.com/problems/broken-calculator/) | [Java](./Java/BrokenCalculator.java) | _O(n)_ | _O(n)_ | Medium | Math | | +| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k/) | [Python](./Python/baseK.py) | _O(n)_ | _O(1)_ | Easy | Math | |
@@ -320,8 +339,11 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands/) | [Java](./Java/NumberOfIslands.java) | O(R \* C) | O(R \* C) | Medium | BFS | | 127 | [Word Ladder](https://leetcode.com/problems/word-ladder/) | [Java](./Java/word-ladder.java) | O(N^2 \* M) | O(N \* M) | Medium | BFS | | 994 | [Rotten Oranges](https://leetcode.com/problems/rotting-oranges/) | [Python](./Python/994_Rotting_Oranges.py) | O(N \* M) | O(N \* M) | Medium | BFS | -| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time/) | [C++](./C++/Network-delay-time.cpp) | _O(V+E))_ | O(V) | Medium | BFS | - 111 | [Min Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [JavaScript](./JavaScript/111-minimum-depth-of-binary-tree.js) | O(nlogn) | O(nlogn) | Easy | BFS +| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time/) | [C++](./C++/Network-delay-time.cpp) | _O(V+E))_ | O(V) | Medium | BFS | +| 111 | [Min Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [JavaScript](./JavaScript/111-minimum-depth-of-binary-tree.js) | O(nlogn) | O(nlogn) | Easy | BFS | +| 100 | [Same Tree](https://leetcode.com/problems/same-tree/) | [C++](https://github.com/codedecks-in/LeetCode-Solutions/blob/master/C%2B%2B/100_Same_Tree.cpp) | O(N) | O(N) | Easy | BFS | + +
⬆️ Back to Top @@ -330,14 +352,16 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Depth-First Search -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | ------------------------------------------------------------------------------------------- | -------------------------------------------------- | ----------- | ----------- | ---------- | --- | ---- | -| 1463 | [Cherry Pickup II](https://leetcode.com/problems/cherry-pickup-ii/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n \* m)_ | _O(n \* m)_ | Hard | DFS | | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [python](./Python/maximum-depth-of-binary-tree.py) | _O(n)_ | _O(n)_ | Easy | DFS | | -| 112 | [Path Sum](https://leetcode.com/problems/path-sum/) | [Java](./Java/path-sum.java) | _O(n)_ | _O(n)_ | Easy | DFS | | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [Java](./Java/Balanced-Binary-Tree.java) | _O(n)_ | _O(n)_ | Easy | DFS | | -| 1376 | [ Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n)_ | _O(n)_ | Medium | DFS | | -|
+| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| ---- | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | ----------- | ----------- | ---------- | --- | ---- | +| 1463 | [Cherry Pickup II](https://leetcode.com/problems/cherry-pickup-ii/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n \* m)_ | _O(n \* m)_ | Hard | DFS | | +| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [python](./Python/maximum-depth-of-binary-tree.py) | _O(n)_ | _O(n)_ | Easy | DFS | | +| 112 | [Path Sum](https://leetcode.com/problems/path-sum/) | [Java](./Java/path-sum.java) | _O(n)_ | _O(n)_ | Easy | DFS | | +| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [Java](./Java/Balanced-Binary-Tree.java) | _O(n)_ | _O(n)_ | Easy | DFS | | +| 1376 | [ Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n)_ | _O(n)_ | Medium | DFS | | +| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands/) | [C++](./C++/number-of-islands.cpp) | _O(m * n)_ | _O(m * n)_ | Medium | DFS | | + +
@@ -350,6 +374,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 037 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver/) | [C++](./C++/Sudoku-Solver.cpp) | _O(n^2)_ | _O(1)_ | Hard | Hash Table | | | 980 | [Unique Paths III](https://leetcode.com/problems/unique-paths-iii/) | [C++](./C++/Unique-Paths-III.cpp) | _O(R * C * 2 ^ (R \* C))_ | _O(R \* C)_ | Hard | DFS, Memoization | | | 39 | [Combination Sum](https://leetcode.com/problems/combination-sum/) | [C++](./C++/combination-sum.cpp) | _O(2^n)_ | _O(n)_ | Medium | Array, Backtracking | | +| 17 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/) | [C++](./C++/letter-combinations-of-a-phone-number.cpp) | _O(4^n)_ | _O(n)_ | Medium | String, Hash Table, Backtracking | |
@@ -372,6 +397,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 174 | [Dungeon Game](https://leetcode.com/problems/dungeon-game/) | [C++](./C++/dungeon-game.pp) | _O(M\*N)_ | _O(M\*N)_ | Hard | Dynamic Programming | | | 070 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | [Java](./Java/climbing-stairs.java) | _O(N)_ | _O(1)_ | Easy | DP | | | 730 | [Count Different Palindromic Subsequences](https://leetcode.com/problems/count-different-palindromic-subsequences/) | [C++](./C++/Count-Different-Palindromic-Subsequences.cpp) | _O(N\*N)_ | _O(N\*N)_ | Hard | DP | | +| 55 | [Jump Game](https://leetcode.com/problems/jump-game/) | [Python](./Python/jumpGame.py) | _O(N)_ | _O(N)_ | Medium | DP | |
@@ -442,54 +468,56 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if ## Authors -* | [Gourav Rusiya](https://github.com/GouravRusiya30/)
+- | [Gourav Rusiya](https://github.com/GouravRusiya30/)

## Contributors -| Name | Country | Programming Language | Where to find you
(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...) | -| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [Gourav R](https://github.com/GouravRusiya30/)
| India | Java | [codedecks](https://www.youtube.com/c/codedecks/)
[Hackerrank](https://www.hackerrank.com/gouravrusiya786)
[LeetCode](https://leetcode.com/rusiya/) | -| [Dima Vishnevetsky](https://github.com/dimshik100)
| Israel | JavaScript | [Twitter](https://twitter.com/dimshik100)
[Facebook](https://www.facebook.com/dimshik) | -| [Anuj Sharma](https://github.com/Optider/)
| India | Python | [Github](https://github.com/Optider) | -| [Lokendra Bohra](https://github.com/lokendra1704/)
| India | Python | [Leetcode](https://t.co/u0OByxhcHA)
[Hackerrank](https://www.hackerrank.com/lokendra17) | -| [Yuri Spiridonov](https://github.com/YuriSpiridonov)
| Russia | Python | [Twitter](https://twitter.com/YuriSpiridonov)
[Leetcode](https://leetcode.com/yurispiridonov/)
[Hackerrank](https://www.hackerrank.com/YuriSpiridonov) | -| [Naveen Kashyap](https://github.com/naveenkash)
| India | Javascript | [Twitter](https://twitter.com/naveen_kashyapp)
[Leetcode](https://leetcode.com/naveenkash/) | -| [Rudra Mishra](https://github.com/Rudra407)
| India | C++ | [Twitter](https://twitter.com/ruDra_Mishra407)
[Leetcode](https://leetcode.com/rudramishra/) | -| [Sachin Singh Negi](https://github.com/sachinnegi)
| India | Python | [Twitter](https://twitter.com/SachinSinghNe17)
[Leetcode](https://leetcode.com/negisachin688/)
[Hackerrrak](https://www.hackerrank.com/negisachin688) | -| [Girish Thatte](https://github.com/girishgr8/)
| India | Java | [Leetcode](https://leetcode.com/girish13/)
[Hackerrank](https://www.hackerrank.com/procoder_13)
[Codechef](https://www.codechef.com/procoder_13) | -| [Kevin Chittilapilly](https://github.com/KevinChittilapilly)
| India | Java | [Leetcode](https://leetcode.com/being_kevin/)
[Hackerrank](https://www.hackerrank.com/ckevinvarghese11)
[Kaggle](https://www.kaggle.com/kevinchittilapilly) | -| [Nour Grati](https://github.com/Nour-Grati)
| Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/)
[Hackerrank](https://www.hackerrank.com/noor_grati)
[Twitter](https://twitter.com/GratiNour1) | -| [Avinash Trivedi](https://github.com/trivediavinash)
| India | C++ | [Leetcode](https://leetcode.com/avi_002/) | -| [Ishika Goel](https://github.com/ishikagoel5628)
| India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) | -| [Fenil Dobariya](https://github.com/ifenil)
| India | Java | [Github](https://github.com/ifenil) | -| [Prashansa Tanwar](https://github.com/prashansatanwar)
| India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) | -| [Ishu Raj](https://github.com/ir2010)
| India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) | -| [Rakesh Bhadhavath](https://github.com/Revenge-Rakesh)
| India | Java | [Leetcode](https://leetcode.com/goal_cracker/) | -| [Tarun Singh](https://github.com/TarunSingh56)
| India | C++ | [Leetcode](https://leetcode.com/_tarun/) | -| [Hardik Gupta](https://github.com/harrdy272)
| India | C++ | [codeforces](https://codeforces.com/profile/harrdy272)
[codechef](https://www.codechef.com/users/hardikg272)
[Hackerrank](https://www.hackerrank.com/hardikg272)
[LeetCode](https://leetcode.com/hardikg272/) | -| [Jaseem ck](https://github.com/Jaseemck)
| India | Python | [Github](https://github.com/Jaseemck) | -| [Ilias Khan](https://github.com/IliasKhan)
| India | C++ | [codechef](https://www.codechef.com/users/iliaskhan)
[Hackerrank](ckerrank.com/iliaskhan57)
[LeetCode](https://leetcode.com/ilias_khan/)
[codeforces](http://codeforces.com/profile/iliaskhan) | -| [Shamoyeeta Saha](https://github.com/Shamoyeeta)
| India | C++ | [Hackerrank](https://www.hackerrank.com/sahashamoyeeta)
[Github](https://github.com/Shamoyeeta) | -| [James Y](https://github.com/jameszu)
| New Zealand | python | [Github](https://github.com/jameszu) | -| [Hamza B](https://github.com/9Hamza)
| Saudi Arabia | Java | [Github](https://github.com/9Hamza) | -| [Meli Haktas](https://github.com/MercerFrey)
| Turkey | python | [Github](https://github.com/MercerFrey) | -| [Saurav Prateek](https://github.com/SauravP97)
| India | Java | [Github](https://github.com/SauravP97)
[Codechef](https://www.codechef.com/users/srvptk)
[Codeforces](https://codeforces.com/profile/srvptk97)
[Leetcode](https://leetcode.com/srvptk97) | -| [Anushka Verma](https://github.com/verma-anushka)
| India | C++ | [Portfolio](https://verma-anushka.github.io/anushkaverma/)
[LeetCode](https://leetcode.com/anushka_verma/) | -| [James H](https://github.com/HoangJames)
| United Kingdom | C++ | [Github](https://github.com/HoangJames) | -| [Franchis N. Saikia](https://github.com/Francode007)
| India | C++ | [Github](https://github.com/Francode007) | -| [Yarncha](https://github.com/yarncha)
| South Korea | C++ | [LeetCode](https://leetcode.com/yamcha/) | -| [Gamez0](https://github.com/Gamez0)
| South Korea | Python | [LeetCode](https://leetcode.com/Gamez0/) | -| [JeongDaHyeon](https://github.com/JeongDaHyeon)
| South Korea | Java | [GitHub](https://github.com/JeongDaHyeon) | -[Aysia](https://www.linkedin.com/in/aysiaelise/)
| USA | JavaScript | [GitHub](https://github.com/aysiae) -| [Poorvi Garg](https://github.com/POORVI111)
| India | C++ | [GitHub](https://github.com/POORVI111) -| [Lakshmanan Meiyappan](https://laxmena.com)
| India | C++ |[Website - Blog](https://laxmena.com)
[GitHub](https://github.com/laxmena)
[LinekdIn](https://www.linkedin.com/in/lakshmanan-meiyappan/) - - - - -
+| Name | Country | Programming Language | Where to find you
(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...) | +| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [Gourav R](https://github.com/GouravRusiya30/)
| India | Java | [codedecks](https://www.youtube.com/c/codedecks/)
[Hackerrank](https://www.hackerrank.com/gouravrusiya786)
[LeetCode](https://leetcode.com/rusiya/) | +| [Dima Vishnevetsky](https://github.com/dimshik100)
| Israel | JavaScript | [Twitter](https://twitter.com/dimshik100)
[Facebook](https://www.facebook.com/dimshik) | +| [Anuj Sharma](https://github.com/Optider/)
| India | Python | [Github](https://github.com/Optider) | +| [Lokendra Bohra](https://github.com/lokendra1704/)
| India | Python | [Leetcode](https://t.co/u0OByxhcHA)
[Hackerrank](https://www.hackerrank.com/lokendra17) | +| [Yuri Spiridonov](https://github.com/YuriSpiridonov)
| Russia | Python | [Twitter](https://twitter.com/YuriSpiridonov)
[Leetcode](https://leetcode.com/yurispiridonov/)
[Hackerrank](https://www.hackerrank.com/YuriSpiridonov) | +| [Naveen Kashyap](https://github.com/naveenkash)
| India | Javascript | [Twitter](https://twitter.com/naveen_kashyapp)
[Leetcode](https://leetcode.com/naveenkash/) | +| [Rudra Mishra](https://github.com/Rudra407)
| India | C++ | [Twitter](https://twitter.com/ruDra_Mishra407)
[Leetcode](https://leetcode.com/rudramishra/) | +| [Sachin Singh Negi](https://github.com/sachinnegi)
| India | Python | [Twitter](https://twitter.com/SachinSinghNe17)
[Leetcode](https://leetcode.com/negisachin688/)
[Hackerrrak](https://www.hackerrank.com/negisachin688) | +| [Girish Thatte](https://github.com/girishgr8/)
| India | Java | [Leetcode](https://leetcode.com/girish13/)
[Hackerrank](https://www.hackerrank.com/procoder_13)
[Codechef](https://www.codechef.com/procoder_13) | +| [Kevin Chittilapilly](https://github.com/KevinChittilapilly)
| India | Java | [Leetcode](https://leetcode.com/being_kevin/)
[Hackerrank](https://www.hackerrank.com/ckevinvarghese11)
[Kaggle](https://www.kaggle.com/kevinchittilapilly) | +| [Nour Grati](https://github.com/Nour-Grati)
| Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/)
[Hackerrank](https://www.hackerrank.com/noor_grati)
[Twitter](https://twitter.com/GratiNour1) | +| [Avinash Trivedi](https://github.com/trivediavinash)
| India | C++ | [Leetcode](https://leetcode.com/avi_002/) | +| [Ishika Goel](https://github.com/ishikagoel5628)
| India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) | +| [Fenil Dobariya](https://github.com/ifenil)
| India | Java | [Github](https://github.com/ifenil) | +| [Prashansa Tanwar](https://github.com/prashansatanwar)
| India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) | +| [Ishu Raj](https://github.com/ir2010)
| India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) | +| [Rakesh Bhadhavath](https://github.com/Revenge-Rakesh)
| India | Java | [Leetcode](https://leetcode.com/goal_cracker/) | +| [Tarun Singh](https://github.com/TarunSingh56)
| India | C++ | [Leetcode](https://leetcode.com/_tarun/) | +| [Hardik Gupta](https://github.com/harrdy272)
| India | C++ | [codeforces](https://codeforces.com/profile/harrdy272)
[codechef](https://www.codechef.com/users/hardikg272)
[Hackerrank](https://www.hackerrank.com/hardikg272)
[LeetCode](https://leetcode.com/hardikg272/) | +| [Jaseem ck](https://github.com/Jaseemck)
| India | Python | [Github](https://github.com/Jaseemck) | +| [Ilias Khan](https://github.com/IliasKhan)
| India | C++ | [codechef](https://www.codechef.com/users/iliaskhan)
[Hackerrank](ckerrank.com/iliaskhan57)
[LeetCode](https://leetcode.com/ilias_khan/)
[codeforces](http://codeforces.com/profile/iliaskhan) | +| [Shamoyeeta Saha](https://github.com/Shamoyeeta)
| India | C++ | [Hackerrank](https://www.hackerrank.com/sahashamoyeeta)
[Github](https://github.com/Shamoyeeta) | +| [James Y](https://github.com/jameszu)
| New Zealand | python | [Github](https://github.com/jameszu) | +| [Hamza B](https://github.com/9Hamza)
| Saudi Arabia | Java | [Github](https://github.com/9Hamza) | +| [Meli Haktas](https://github.com/MercerFrey)
| Turkey | python | [Github](https://github.com/MercerFrey) | +| [Saurav Prateek](https://github.com/SauravP97)
| India | Java | [Github](https://github.com/SauravP97)
[Codechef](https://www.codechef.com/users/srvptk)
[Codeforces](https://codeforces.com/profile/srvptk97)
[Leetcode](https://leetcode.com/srvptk97) | +| [Anushka Verma](https://github.com/verma-anushka)
| India | C++ | [Portfolio](https://verma-anushka.github.io/anushkaverma/)
[LeetCode](https://leetcode.com/anushka_verma/) | +| [James H](https://github.com/HoangJames)
| United Kingdom | C++ | [Github](https://github.com/HoangJames) | +| [Franchis N. Saikia](https://github.com/Francode007)
| India | C++ | [Github](https://github.com/Francode007) | +| [Yarncha](https://github.com/yarncha)
| South Korea | C++ | [LeetCode](https://leetcode.com/yamcha/) | +| [Gamez0](https://github.com/Gamez0)
| South Korea | Python | [LeetCode](https://leetcode.com/Gamez0/) | +| [JeongDaHyeon](https://github.com/JeongDaHyeon)
| South Korea | Java | [GitHub](https://github.com/JeongDaHyeon) | +| [Aysia](https://www.linkedin.com/in/aysiaelise/)
| USA | JavaScript | [GitHub](https://github.com/aysiae) | +| [Poorvi Garg](https://github.com/POORVI111)
| India | C++ | [GitHub](https://github.com/POORVI111) | +| [Lakshmanan Meiyappan](https://laxmena.com)
| India | C++ | [Website - Blog](https://laxmena.com)
[GitHub](https://github.com/laxmena)
[LinekdIn](https://www.linkedin.com/in/lakshmanan-meiyappan/) | +| [Sachin_Upadhyay](https://github.com/sachsbu)
| India | Java | [GitHub](https://github.com/sachsbu) +| [Amisha Sahu](https://github.com/Amisha328)
| India | C++ | [CodeChef](https://www.codechef.com/users/amisha328)
[LeetCode](https://leetcode.com/Mishi328/)
[HackerRank](https://www.hackerrank.com/amishasahu328) +| [Shrimadh V Rao](https://github.com/Shrimadh)
| India | C++ | [GitHub](https://github.com/Shrimadh) +| [Shreyas Shrawage](https://github.com/shreyventure)
| India | Python | [CodeChef](https://www.codechef.com/users/shreyventure)
[LeetCode](https://leetcode.com/shreyventure/)
[HackerRank](https://www.hackerrank.com/shreyas_shrawage) +| [Surbhi Mayank](https://github.com/surbhi2408)
| India | C++ | [GitHub](https://github.com/surbhi2408) +| [Amrit Kumar](https://github.com/amrit-GH23)
| India | C++ | [CodeChef](https://www.codechef.com/users/amrit_kumar08)
[Linkedin](https://www.linkedin.com/in/amrit-kumar-28053b253/) +