diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..0b9daa6e --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: [codedecks-in] +custom: ["https://paypal.me/codedecks"] diff --git a/.github/config.yml b/.github/config.yml new file mode 100644 index 00000000..bb12472e --- /dev/null +++ b/.github/config.yml @@ -0,0 +1,18 @@ +# Configuration for behaviorbot - https://github.com/behaviorbot/ + +# Comment to be posted to on first time issues +newIssueWelcomeComment: > + # Thanks for helping us improve and opening your first issue here! Don't forget to give us a 🌟 to support us. + + While you're waiting, I just wanted to make sure you've had a chance to look at our + [Readme](https://github.com/codedecks-in/LeetCode-Solutions/blob/master/README.md) and [Pull Request Guidelines](https://github.com/codedecks-in/LeetCode-Solutions/blob/master/PULL_REQUEST_PROCESS.md). + +# Comment to be posted to on PRs from first time contributors in your repository +newPRWelcomeComment: > + I can tell this is your first pull request! Thank you I'm so honored. :tada::tada::tada: + I'll take a look at it ASAP! + +# Comment to be posted to on pull requests merged by a first time user +firstPRMergeComment: > + Your code looks great! Congrats, I've gone ahead and merged your first pull request! Keep it up! + ![alt text](https://media.giphy.com/media/d31w24psGYeekCZy/giphy.gif "WOOHOO") 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> threeSum(vector& nums) { + vector > res; + + std::sort(nums.begin(), nums.end()); + + for (int i = 0; i < nums.size(); i++) { + + int target = -nums[i]; + int front = i + 1; + int back = nums.size() - 1; + + while (front < back) { + + int sum = nums[front] + nums[back]; + + // Finding answer which start from number nums[i] + if (sum < target) + front++; + + else if (sum > target) + back--; + + else { + vector triplet(3, 0); + triplet[0] = nums[i]; + triplet[1] = nums[front]; + triplet[2] = nums[back]; + res.push_back(triplet); + + // Processing duplicates of Number 2 + // Rolling the front pointer to the next different number forwards + while (front < back && nums[front] == triplet[1]) front++; + + // Processing duplicates of Number 3 + // Rolling the back pointer to the next different number backwards + while (front < back && nums[back] == triplet[2]) back--; + } + + } + + // Processing duplicates of Number i + while (i + 1 < nums.size() && nums[i + 1] == nums[i]) + i++; + + } + + return res; + } +}; \ No newline at end of file diff --git a/C++/Baseball-Game.cpp b/C++/Baseball-Game.cpp new file mode 100644 index 00000000..16898b7a --- /dev/null +++ b/C++/Baseball-Game.cpp @@ -0,0 +1,33 @@ +class Solution { +public: + int calPoints(vector& ops) { + stack s; + auto it=ops.begin(); + while(it!=ops.end()){ + if(*it=="+"){ //if char is + then new record is sum of last two records + int val1=s.top(); + s.pop(); + int val2=s.top(); + s.push(val1); + s.push(val1+val2); + } + else if(*it=="D"){ //if char is D then new record is twice the last record + s.push(2*s.top()); + } + else if(*it=="C"){ //if char is C then the last record is invalidated , hence popped + s.pop(); + } + else{ // if none of these conditions occur then just push the new record to stack + s.push(stoi(*it)); + } + it++; + } + int count=0; + while(!s.empty()) //iteratively pop the top value of the stack and add it to the total + { + count+=s.top(); + s.pop(); + } + return count; + } +}; \ No newline at end of file diff --git a/C++/Binary-Tree-Level-Order-Traversal.cpp b/C++/Binary-Tree-Level-Order-Traversal.cpp new file mode 100644 index 00000000..2a3e1d2b --- /dev/null +++ b/C++/Binary-Tree-Level-Order-Traversal.cpp @@ -0,0 +1,61 @@ +/* +Problem: +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 +*/ + + +/* +Space Complexity : O(N) +Time Complexity : O(N) +Difficulty level : Medium +*/ + +class Solution { +public: + void fun( map>&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++/BinarySearch.cpp b/C++/BinarySearch.cpp new file mode 100644 index 00000000..e291ad38 --- /dev/null +++ b/C++/BinarySearch.cpp @@ -0,0 +1,33 @@ +//Problem Statement: Binary Search + +// Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, then return its index, otherwise return -1. + + +//Solution: +class Solution { +public: + int search(vector& nums, int target) { + + int si=0, ei=nums.size()-1; + + while(si <= ei) { + // index of the middle element + int mid = si + (ei-si)/2; + + // found target element + if(nums[mid] == target) { + return mid; + } else if(nums[mid] < target) { // target on right side of middle element + si += 1; + } else { // target on left side of middle element + ei -= 1; + } + } + + // target element not present in given array + return -1; + } +}; + +// Time Complexity: O(log(n)) + diff --git a/C++/Count-Different-Palindromic-Subsequences.cpp b/C++/Count-Different-Palindromic-Subsequences.cpp new file mode 100644 index 00000000..7f918cfd --- /dev/null +++ b/C++/Count-Different-Palindromic-Subsequences.cpp @@ -0,0 +1,90 @@ +/* +Difficulty: Hard +Runtime: beat 100% cpp code. +submission-url: https://leetcode.com/submissions/detail/158074027 +*/ +/*Given a string S, find the number of different non-empty palindromic subsequences in S, and return that number modulo 10^9 + 7. +A subsequence of a string S is obtained by deleting 0 or more characters from S. +A sequence is palindromic if it is equal to the sequence reversed. +Two sequences A_1, A_2, ... and B_1, B_2, ... are different if there is some i for which A_i != B_i. +Example: +Input: +S = 'bccb' +Output: 6 +*/ +/* +create 2d dp. +dp[i][j] will have the number of palindromes of the input_string[i] to input_string[j]. +for string bccb - +dp: +1 2 3 6 +0 1 2 3 +0 0 1 2 +0 0 0 1 +you will find here..similer logic like finding longest palindromic subsequence.. +*/ + +class Solution { +public: + int countPalindromicSubsequences(string s) { + long n=s.size(); + // Created a db and initialize to 0 + long dp[n][n]; + for(int i=0;i=0;i--) + { + for(int j=i;ji && s[high]!=s[j]){ + high--; + } + + if(low>high) + { + dp[i][j] = dp[i+1][j-1]*2 + 2; // no other same char is there..between i, j + // in case bccb,i=0,j=3, dp[1][2] = 2(c, cc)...so, dp[0][3] = 2*2+2(b, bcb, bccb, c, cc, bb) + } + else if(low == high) + { + dp[i][j] = dp[i+1][j-1]*2 + 1; // 1 same char is there..between i, j + } // in case bcbb,i=0,j=3, dp[1][2] = 2(c, b)...so, dp[0][3] = 2*2+1(b, bcb, bb, c, bbb) + else + { + dp[i][j] = (dp[i+1][j-1]*2 - dp[low+1][high-1]); // more than 1 same char is there..between i, j + // in case bbbb,i=0,j=3, dp[1][2] = 2(b, bb)...so, dp[0][3] = 2*2 - 0(b, bb, bbb, bbbb) + } + } + else + { + dp[i][j] = dp[i][j-1] + dp[i+1][j] - dp[i+1][j-1]; //edge chars does not mach... + } // in case abcd,i=0,j=3, dp[0][2] = 3, dp[1][3] = 3, dp[1][2] = 2...so, dp[0][3] = 3 + 3 - 2(a, b, c, d) + + // just safe..as we are subtracting..earlier in code + if(dp[i][j]<0) + dp[i][j]+=1000000007; + + dp[i][j]=dp[i][j]%1000000007; // ans could be very big + + } + + } + return dp[0][n-1];//ans + } +}; diff --git a/C++/Course-Schedule-II.cpp b/C++/Course-Schedule-II.cpp new file mode 100644 index 00000000..3f62059a --- /dev/null +++ b/C++/Course-Schedule-II.cpp @@ -0,0 +1,47 @@ +//CPP BFS solution +//Time complexity O(V+E) +//Space Complexity O(V) +class Solution { +public: + vector findOrder(int numCourses, vector>& prerequisites) { + int n=numCourses; + int m=prerequisites.size(); + vectorans; + vectorv(n,0); + vector>g(n); + + + for(int i=0;iq; + for(int i=0;i>& adjlist, vector& visited, int i) { + + // base condition + if(visited[i]==1) return false; + visited[i]=1; // mark as being visited + + for(int a:adjlist[i]) { + if(!dfs(adjlist, visited, a)) // dfs(adjlist, visited, a) == false + return false; + } + + visited[i] = 2; // mark as visited + return true; + } + + + bool canFinish(int numc, vector>& prereq) { + + // numc: numCourses + // prereq: prerequisites + + // create adjacency list + vector> adjlist(numc, vector()); + for(vector& p:prereq) + adjlist[p[0]].push_back(p[1]); + + vector visited(numc, 0); + // unvisited: 0 + // being visited: 1 + // completely visited: 2 + for(int i=0; i& logs) { + stack s; //stack s is initialized and stack is empty when you are on main folder + for(int i=0;i parent; + vector> adjacent_matrix; + + vector steps_taken; + vector min_steps_taken; + + vector visited; + + void initParent(int& n) { + for (int i = 0; i <= n; ++i) + { + parent.push_back(i); + } + adjacent_matrix = vector>(n); + + steps_taken = vector(n); + min_steps_taken = vector(n); + + visited = vector(n); + } + + void addEdge(int& x, int& y) { + adjacent_matrix[x].push_back(y); + adjacent_matrix[y].push_back(x); + } + + void dfs(int& vertex, vector>& ans) { + visited[vertex] = true; + + steps_taken[vertex] = min_steps_taken[vertex] = steps++; + + for (auto adj_vertex : adjacent_matrix[vertex]) { + if (!visited[adj_vertex]) { + parent[adj_vertex] = vertex; + + dfs(adj_vertex, ans); + + min_steps_taken[vertex] = min(min_steps_taken[vertex], min_steps_taken[adj_vertex]); + + // check if the edge is crticial for network or not + if (min_steps_taken[adj_vertex] > steps_taken[vertex]) { + ans.push_back({vertex, adj_vertex}); + } + + } else { + if (parent[vertex] != adj_vertex) { + min_steps_taken[vertex] = min(min_steps_taken[vertex], steps_taken[adj_vertex]); + } + } + } + } + + vector> criticalConnections(int n, vector>& connections) { + vector> ans; + initParent(n); + + for (auto connection : connections) { + addEdge(connection[0], connection[1]); + } + + for (int i = 0; i < n; ++i) + { + if (visited[i]) continue; + dfs(i, ans); + } + + return ans; + } +}; 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++/Detect-Capital.cpp b/C++/Detect-Capital.cpp new file mode 100644 index 00000000..c5332819 --- /dev/null +++ b/C++/Detect-Capital.cpp @@ -0,0 +1,19 @@ +// Problem URL: https://leetcode.com/problems/single-number-iii/ +/* + * Runtime - 0ms + * Memory - 5.9mb + */ + +class Solution { +public: + bool detectCapitalUse(string word) { + bool all_caps = 1; + bool all_small = 1; + bool first_letter_caps = isupper(word[0]); + + for(int i=1; i 1 +// B -> 2 +// C -> 3 +// ... +// Z -> 26 +// AA -> 27 +// AB -> 28 +// ... + +//Solution: +class Solution { +public: + int titleToNumber(string s) { + + int power=0, colnum=0; + + while(!s.empty()) { + + colnum += (s[s.size()-1] - 'A' + 1)*pow(26, power); + power++; + s=s.substr(0, s.size()-1); + + } + + return colnum; + } +}; + +//Complexity: O(n) diff --git a/C++/Find-The-Difference.cpp b/C++/Find-The-Difference.cpp new file mode 100644 index 00000000..270f8275 --- /dev/null +++ b/C++/Find-The-Difference.cpp @@ -0,0 +1,42 @@ +//time complexity O(n+m) where n and m are the number of input characters in each input string respectively +//space compexity is O(1) since there is a limit on number of possible unique characters +//loop through the first string and add a count of characters to hashmap +//loop through second string and for each letter lookup in hashmap. If found, decrement the count in the hasmap. If the count <0 for any letter then we have found our extra character +//else if the letter cannot be found in our hashmap, then this must be the extra character +//Otherwise if no differences can be found between the two input strings we just return null character + + + +class Solution { +public: + char findTheDifference(string s, string t) { + + char returnChar= '\0'; + std::unordered_map ourMap; + + //count the letters in the input string and add it to map + for (const char& letter:s) { + + if(ourMap.find(letter)==ourMap.end()){ ourMap[letter]=1;} + else{ourMap[letter]++;} + } + + + //compare with letters in other string + for (const char& letter:t){ + + //if you can find the letter then decrement it + if(ourMap.find(letter)!=ourMap.end()) { + + ourMap[letter]--; + if(ourMap[letter]<0) { return letter; } + + } + + else{return letter;} + } + + return returnChar; + + } +}; \ No newline at end of file diff --git a/C++/Is-Graph-Bipartite.cpp b/C++/Is-Graph-Bipartite.cpp new file mode 100644 index 00000000..fb0ad1e7 --- /dev/null +++ b/C++/Is-Graph-Bipartite.cpp @@ -0,0 +1,39 @@ +//CPP BFS solution +//Time complexity O(V+E) +//Space Complexity O(V) +class Solution { +public: + bool isBipartite(vector>& graph) { + int n=graph.size(); + vectorv(n,false); + vectorc(n,-1); + queueq; + + for(int i=0;i& h) { + int n = h.size(); + + stack s; + int curr = 0; + int ans = 0; + int tp; + int i = 0; + while (i < n) { + if (s.empty() || h[s.top()] <= h[i]) s.push(i++); + else { + tp = s.top(); s.pop(); + if (s.empty()) curr = h[tp] * i; + else curr = h[tp] * (i - s.top() - 1); + ans = max(ans, curr); + } + } + while (!s.empty()) { + tp = s.top(); s.pop(); + if (s.empty()) curr = h[tp] * i; + else curr = h[tp] * (i - s.top() - 1); + ans = max(ans, curr); + } + return ans; + } +}; \ No newline at end of file diff --git a/C++/Longest-Mountain-in-Array.cpp b/C++/Longest-Mountain-in-Array.cpp new file mode 100644 index 00000000..5ceb80a4 --- /dev/null +++ b/C++/Longest-Mountain-in-Array.cpp @@ -0,0 +1,62 @@ +/* +Difficulty: medium +runtime: 36ms +*/ +/* +Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold:B.length >= 3 +There exists some 0 < i < B.length - 1 such that B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1] +(Note that B could be any subarray of A, including the entire array A.) +Given an array A of integers, return the length of the longest mountain. Return 0 if there is no mountain. + +Note: +0 <= A.length <= 10000 +0 <= A[i] <= 10000 + +Example 1: + Input: [2,1,4,7,3,2,5] + Output: 5 + Explanation: The largest mountain is [1,4,7,3,2] which has length 5. + +Example 2: + Input: [2,2,2] + Output: 0 + Explanation: There is no mountain. + +Followup: +Can you solve it using only one pass? YES +Can you solve it in O(1) space? YES +___________________________________________________________________________________________________________________________ +CodeExplain: + while treversing the array..we have to just count increasing and decreasing numbers. + and maximize the addition of increasing and decreasing numbers. + +*/ + +class Solution { +public: + int longestMountain(vector& A) { + int n=A.size(); + if(n<3) + return 0; + int ans = 0, left = 0, right = 0;// left = increasing, right = decreasing + for(int i=1;iA[i-1]){ //increasing count + if(right){ + left=0; + right=0; + } + left += (1 + (left==0)); + } + else if(A[i] val <= l2 -> val) + { + l1 -> next = mergeTwoLists(l1 -> next, l2); + return l1; + } + + else + { + l2 -> next = mergeTwoLists(l1, l2 -> next); + return l2; + } + } +}; + + diff --git a/C++/Most-Stones-Removed-with-Same-Row-or-Column.cpp b/C++/Most-Stones-Removed-with-Same-Row-or-Column.cpp new file mode 100644 index 00000000..f23db3c9 --- /dev/null +++ b/C++/Most-Stones-Removed-with-Same-Row-or-Column.cpp @@ -0,0 +1,72 @@ +// C++ Union Find Solution +// Time Complexity: O(V) +// Space Complexity: O(V) + +class Solution { +public: + vector parent; + void initParent(int n) { + for (int i = 0; i <= n; ++i) + { + parent.push_back(i); + } + } + + int find_parent(int& x) { + if (parent[x] == x) return x; + parent[x] = find_parent(parent[x]); + return parent[x]; + } + + bool unionEdge(int& x, int& y) { + int parent_x = find_parent(x); + int parent_y = find_parent(y); + + if (parent_x == parent_y) return false; + + if (parent_x > parent_y) parent[parent_x] = parent_y; + else parent[parent_y] = parent_x; + + return true; + } + + // map to store the index of first occurence of parent of the current index + unordered_map rows, cols; + + int removeStones(vector>& stones) { + initParent(stones.size()); + + for (int k = 0; k < stones.size(); k++) { + int i = stones[k][0], j = stones[k][1]; + int par_i = INT_MAX, par_j = INT_MAX; + + if (rows.find(i) == rows.end()) rows[i] = k; + else par_i = rows[i]; + + if (cols.find(j) == cols.end()) cols[j] = k; + else par_j = cols[j]; + + if (par_i != INT_MAX) + unionEdge(par_i, k); + + if (par_j != INT_MAX) + unionEdge(par_j, k); + } + + // ans represent number of disjoint sets + int ans = 0; + rows.clear(); cols.clear(); + unordered_set uniq_parents; + + for (int k = 0; k < stones.size(); k++) { + int par_i = find_parent(k); + + if (uniq_parents.find(par_i) == uniq_parents.end()) { + ans++; + uniq_parents.insert(par_i); + } + } + + return stones.size() - ans; + } +}; \ No newline at end of file diff --git a/C++/Move-Zeroes.cpp b/C++/Move-Zeroes.cpp new file mode 100644 index 00000000..a65ad19e --- /dev/null +++ b/C++/Move-Zeroes.cpp @@ -0,0 +1,23 @@ + +//Problem Statement: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. + +//Solution: +class Solution { +public: + void moveZeroes(vector& nums) { + int i = 0; + for (int j = 0; j < nums.size(); j++) { + // Bring all non zero numbers to the start of the array + if (nums[j] != 0) { + nums[i++] = nums[j]; + } + } + + while(i>& times, int N, int K) { + vector d(N + 1, INT_MAX); + d[K] = 0; + for (int i = 0; i < N; ++i) { + for (int j = 0; j < times.size(); ++j) { + if (d[times[j][1]] > d[times[j][0]] + times[j][2]) { + d[times[j][1]] = d[times[j][0]] + times[j][2]; + } + } + } + + int a = *max_element(d.begin() + 1, d.end()); + return a >= INT_MAX ? -1 : a; + } +}; \ No newline at end of file diff --git a/C++/Number-Complement.cpp b/C++/Number-Complement.cpp new file mode 100644 index 00000000..4af92301 --- /dev/null +++ b/C++/Number-Complement.cpp @@ -0,0 +1,20 @@ +// Problem URL: https://leetcode.com/problems/single-number-iii/ +/* + * Runtime - 0ms + * Memory - 5.8mb + */ + +class Solution { +public: + int findComplement(int num) { + int inv = 0, iter = 0; + int reminder; + while(num) { + inv = inv | ((1 - (num % 2))< +class RecentCounter { + deque req; +public: + RecentCounter() { + req={}; + } + + int ping(int t) { + req.push_back(t); + while(req.front() < t-3000) req.pop_front(); + return req.size(); + } +}; + +/** + * Your RecentCounter object will be instantiated and called as such: + * RecentCounter* obj = new RecentCounter(); + * int param_1 = obj->ping(t); + */ diff --git a/C++/Path-Sum-II.cpp b/C++/Path-Sum-II.cpp new file mode 100644 index 00000000..08ed269c --- /dev/null +++ b/C++/Path-Sum-II.cpp @@ -0,0 +1,37 @@ +//CPP DFS solution +//Time complexity O(V+E) +//Space Complexity O(V) +class Solution { +public: + void dfs(vector>&v, vectork,TreeNode*r,int s){ + if(r==NULL){ + return; + } + if(s==r->val&&r->left==NULL&&r->right==NULL){ + k.push_back(r->val); + v.push_back(k); + //k.clear(); + return; + + } + else if(s!=r->val&&r->left==NULL&&r->right==NULL){ + return; + } + + k.push_back(r->val); + s-=r->val; + dfs(v,k,r->left,s); + dfs(v,k,r->right,s); + + + + return; + + } + vector> pathSum(TreeNode* root, int sum) { + vector>v; + vectork; + dfs(v,k,root,sum); + return v; + } +}; \ No newline at end of file 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 new file mode 100644 index 00000000..52808d2d --- /dev/null +++ b/C++/Remove-Covered-Intervals.cpp @@ -0,0 +1,58 @@ +//Problem Statement: Remove Covered Intervals + +// Given a list of intervals, remove all intervals that are covered by another interval in the list. + +// Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d. + +// After doing so, return the number of remaining intervals. + +//Solution: +class Solution { +public: + int removeCoveredIntervals(vector>& intervals) { + + int ans=0; + for(int i=0; i= intervals[j][0] && intervals[i][1] <= intervals[j][1]) { + // cout << i << endl; + ans++; break; + } + } + } + + return intervals.size()-ans; + } +}; + +//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++/Shortest-Bridge.cpp b/C++/Shortest-Bridge.cpp new file mode 100644 index 00000000..4e03b4b7 --- /dev/null +++ b/C++/Shortest-Bridge.cpp @@ -0,0 +1,93 @@ +// C++ DFS + BFS Solution +// Time Complexity : O(V) +// Space Complexity : O(V) + +class Solution { +public: + vector del_i = {1, 0, -1, 0}; + vector del_j = {0, 1, 0, -1}; + + bool checkWithinBounds(int i, int j, int row, int col) { + if (i < 0 || j < 0 || i >= row || j >= col) return false; + return true; + } + + void markIsland(vector>& A, int i, int j) { + A[i][j] = -1; + + for (int k = 0; k < 4; ++k) + { + int next_i = i + del_i[k]; + int next_j = j + del_j[k]; + + if (checkWithinBounds(next_i, next_j, A.size(), A[0].size()) && A[next_i][next_j] == 1) + markIsland(A, next_i, next_j); + } + + } + + int shortestBridge(vector>& A) { + int r = A.size(); + int c = A[0].size(); + + // mark island of one group as -1 + int flag = 0; + for (int i = 0; i < r; ++i) + { + for (int j = 0; j < c; ++j) + { + if (A[i][j] == 1) { + flag = 1; + markIsland(A, i, j); + break; + } + } + + if (flag) break; + } + + // queue that represent flips on a particular path + queue> q; + + for (int i = 0; i < r; ++i) + { + for (int j = 0; j < c; ++j) + { + if (A[i][j] == -1) { + q.push({i * r + j, 0}); + } + } + } + + while (!q.empty()) { + int index = q.front().first; + int i = index / r; + int j = index % r; + + int flips = q.front().second; + + q.pop(); + + for (int k = 0; k < 4; ++k) + { + int next_i = i + del_i[k]; + int next_j = j + del_j[k]; + int next_index = next_i * r + next_j; + + if (checkWithinBounds(next_i, next_j, r, c)) { + if (A[next_i][next_j] == 1) return flips; + + if (A[next_i][next_j] == -1) continue; + + q.push({next_index, flips + 1}); + + A[next_i][next_j] = -1; + } + } + + + } + return -1; + + } +}; diff --git a/C++/Single-Number-II.cpp b/C++/Single-Number-II.cpp new file mode 100644 index 00000000..5f58db67 --- /dev/null +++ b/C++/Single-Number-II.cpp @@ -0,0 +1,17 @@ +// Leetcode URL: https://leetcode.com/problems/single-number-ii +/* + * Runtime - 4ms + * Memory - 9.5 + */ + +class Solution { +public: + int singleNumber(vector& nums) { + int a=0, b=0; + for(int num: nums) { + a = b & (a^num); + b = a | (b^num); + } + return b; + } +}; \ No newline at end of file diff --git a/C++/Single-Number-III.cpp b/C++/Single-Number-III.cpp new file mode 100644 index 00000000..339e7ea2 --- /dev/null +++ b/C++/Single-Number-III.cpp @@ -0,0 +1,36 @@ +// Problem URL: https://leetcode.com/problems/single-number-iii/ +/* + * Runtime - 8ms + * Memory - 10mb + */ + +class Solution { +public: + vector singleNumber(vector& nums) { + int xor_all = 0; + // Get the XOR value of all the numbers in the vector + for(int num: nums) xor_all ^= num; + // xor_all will contain a^b, where a and b are repeated only once. + // if value of a bit in xor is 1, then it means either a or b has + // 1 in that position, but not both. We can use this to find the answer. + int setbit = 1; + // Find the first position in xor_all where the value is 1 + while((setbit & xor_all) == 0) + setbit <<= 1; + + vector result(2); + + // We basically split the numbers into two sets. + // All numbers in first set will have a bit in the setbit position. + // Second set of numbers, will have 0 in the setbit position. + for(int num: nums) { + if(num & setbit) { + result[0] ^= num; + } else { + result[1] ^= num; + } + } + + return result; + } +}; \ 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++/Time-Needed-To-Inform-All-Employees.cpp b/C++/Time-Needed-To-Inform-All-Employees.cpp new file mode 100644 index 00000000..b1165d9e --- /dev/null +++ b/C++/Time-Needed-To-Inform-All-Employees.cpp @@ -0,0 +1,29 @@ +//CPP DFS SOLUTION + +// Problem statement: Return the no of mins required to inform all employees about the urgent news + +class Solution { +public: + vector adjList[100005]; + + int dfs(int headID, vector& informTime) + { + int maxTime=0; + for(auto employee : adjList[headID]) + { + maxTime=max(maxTime, dfs(employee, informTime)); + } + return informTime[headID] + maxTime; + } + int numOfMinutes(int n, int headID, vector& manager, vector& informTime) { + for(int i=0;i +#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 asteroidCollision(vector& asteroids) { + stack s; + + for(int i=0;i0) + { + s.push(asteroids[i]); + } + else + { + while(true) + { + int top = s.top(); + + if(top<0) + { + s.push(asteroids[i]); + break; + } + else if(top==-asteroids[i]) + { + s.pop(); + break; + } + else if(top>(-asteroids[i])) + { + break; + } + else + { + s.pop(); + if(s.empty()) + { + s.push(asteroids[i]); + break; + } + } + } + } + } + + vector output(s.size(),0); + + for(int i=s.size()-1;i>=0;i--) + { + output[i]=s.top(); + s.pop(); + } + + return output; + + +} +}; \ No newline at end of file diff --git a/C++/brick-wall.cpp b/C++/brick-wall.cpp index ebbfa401..cf50b0c9 100644 --- a/C++/brick-wall.cpp +++ b/C++/brick-wall.cpp @@ -26,3 +26,22 @@ class Solution { return (n-maxcount); } }; + +Reduced Code for the given problem that reduces one for loop and also has less auxiliary space! + +// Time: O(n), n is the total number of the bricks +// Space: O(m), m is the total number different widths + +class Solution { +public: + int leastBricks(vector>& 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++/decode-string.cpp b/C++/decode-string.cpp new file mode 100644 index 00000000..66b9997b --- /dev/null +++ b/C++/decode-string.cpp @@ -0,0 +1,32 @@ +class Solution { +public: + string decodeString(string s) { + stack chars; + stack nums; + string res; + int num = 0; + for(char c : s) { + if(isdigit(c)) { + num = num*10 + (c-'0'); + } + else if(isalpha(c)) { + res.push_back(c); + } + else if(c == '[') { + chars.push(res); + nums.push(num); + res = ""; + num = 0; + } + else if(c == ']') { + string tmp = res; + for(int i = 0; i < nums.top()-1; ++i) { + res += tmp; + } + res = chars.top() + res; + chars.pop(); nums.pop(); + } + } + return res; + } +}; \ No newline at end of file diff --git a/C++/dungeon-game.cpp b/C++/dungeon-game.cpp new file mode 100644 index 00000000..ed2d621e --- /dev/null +++ b/C++/dungeon-game.cpp @@ -0,0 +1,64 @@ +//https://leetcode.com/problems/dungeon-game/ +////Difficulty Level: Hard +//Tags: Dynamic Programming +//Time complexity: O(m*n) +//Space complexity: O(m*n) +//bottom-up DP approach +class Solution +{ + public: + int calculateMinimumHP(vector>& dungeon) + { + int m = dungeon.size(); + if(r==0) //empty dungeon + return 0; + + int n = dungeon[0].size(); + + //dp[i][j] --> min health req to reach the princess with starting cell as (i,j) -1 + vector > dp(r, vector(c)); + + for (int i = m-1; i>=0; i--) //traversing the array from bottom + { + for (int j = n-1; j>=0; j--) + { + //if starting from last cell, + //if value at last cell is -ve, health req. is 1+abs(value) + //if value at last cell is +ve, health req. is 0+1 + if (i == m-1 && j == n-1) + { + dp[i][j] = min(0, dungeon[i][j]); + } + + //if starting from last row, + //total health req. is sum of curr cell value and health req. at next cell + //if the sum is +ve, health req. is 0+1 + //if the sum is -ve, health req. is 1+abs(sum) + else if (i == m-1) + { + dp[i][j] = min(0, dungeon[i][j]+dp[i][j+1]); + } + + //if starting from last column, + //total health req. is sum of curr cell value and health req. at next cell + //if the sum is +ve, health req. is 0+1 + //if the sum is -ve, health req. is 1+abs(sum) + else if (j == n-1) + { + dp[i][j] = min(0, dungeon[i][j]+dp[i+1][j]); + } + + //if starting from any other cell, + //make a choice to go to the cell with less req. health(more positive dp value) after the curr cell + //the req. health is either 0 or sum of the curr cell value and health req. at next chosen cell + else + { + dp[i][j] = min(0, dungeon[i][j]+max(dp[i][j+1],dp[i+1][j])); + } + } + } + //actual starting point is (0,0), so return abs(dp(0,0))+1 + //1 is added because the knight needs to have atleast 1 health to survive, else he will die + return abs(dp[0][0])+1; + } +}; diff --git a/C++/k-closest-points-to-origin.cpp b/C++/k-closest-points-to-origin.cpp new file mode 100644 index 00000000..4e9f24b0 --- /dev/null +++ b/C++/k-closest-points-to-origin.cpp @@ -0,0 +1,24 @@ +/*We have a list of points on the plane. Find the K closest points to the origin (0, 0). + +(Here, the distance between two points on a plane is the Euclidean distance.) + +You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in.) */ + + + +class Solution { +public: + vector> kClosest(vector>& points, int K) { + vector> vec; + for(int i=0;i> f;//final points vector + for(int i=0;i 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++/merge-k-sorted-lists.cpp b/C++/merge-k-sorted-lists.cpp new file mode 100644 index 00000000..7c52ba33 --- /dev/null +++ b/C++/merge-k-sorted-lists.cpp @@ -0,0 +1,49 @@ +/** + * 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: + //Fucntion to append node at the end of lisked list + struct ListNode *begg(struct ListNode *head, int x){ + struct ListNode *temp = new ListNode(x); + //If there is no node + if(head==NULL){ + head=temp; + return head; + } + //If nodes already present + struct ListNode *ptr=head; + while(ptr->next){ + ptr=ptr->next; + } + ptr->next=temp; + return head; + } + ListNode* mergeKLists(vector& lists) { + //Using multiset s it will allow duplicate values and will store them in sorted order. + multiset s; + //Adding values to multiset. + for(int i=0;ival); + p1=p1->next; + } + } + //Initializing the head of linked list. + struct ListNode *head2=NULL; + //Appending nodes in the linked list from multiset. + for(auto it=s.begin();it!=s.end();++it){ + head2=begg(head2,*it); + cout<<*it<<" "; + } + return head2; + } +}; diff --git a/C++/minimum-add-to-make-parentheses-valid.cpp b/C++/minimum-add-to-make-parentheses-valid.cpp new file mode 100644 index 00000000..e14e1bc3 --- /dev/null +++ b/C++/minimum-add-to-make-parentheses-valid.cpp @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ + +class Solution { +public: + int minAddToMakeValid(string S) { + int result = 0; + + stack s; //stack to save '(' + + for (int i = 0; i < S.size(); i++) + { + if (S[i] == '(') { + s.push('('); + } + else { + if (s.empty()) { + result++; + } + else { + s.pop(); + } + } + } + + result = result + s.size(); + + return result; + } +}; diff --git a/C++/minimum-remove-to-make-valid-parentheses.cpp b/C++/minimum-remove-to-make-valid-parentheses.cpp new file mode 100644 index 00000000..370a3345 --- /dev/null +++ b/C++/minimum-remove-to-make-valid-parentheses.cpp @@ -0,0 +1,35 @@ +class Solution { +public: + string minRemoveToMakeValid(string s) { + stack stack_for_index; //stack to save index of '(' + string result_string = ""; + + // count wrong parentheses with stack & make string + for (int i = 0; i < s.size(); i++) + { + if (s[i] == '(') { + stack_for_index.push(result_string.size()); + result_string.push_back(s[i]); + } + else if (s[i] == ')') { + if (!stack_for_index.empty()) { + stack_for_index.pop(); + result_string.push_back(s[i]); + } + } + else { + result_string.push_back(s[i]); + } + } + // now "stack_for_characters.size()" is the number of wrong "left" parentheses + + // remove wrong left parentheses + while (!stack_for_index.empty()) + { + result_string.erase(stack_for_index.top(), 1); + stack_for_index.pop(); + } + + return result_string; + } +}; \ No newline at end of file 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 s; + string answer=""; + for(int i=0;i& nums, int val) { + int slow=0; + int fast = 0; + + + while (fast < nums.size()){ + + if (nums[fast]!=val){nums[slow++]=nums[fast];} + fast++; + + } + + return slow; + + } +}; \ No newline at end of file diff --git a/C++/two-sum.cpp b/C++/two-sum.cpp index 98ec9a93..a6489044 100644 --- a/C++/two-sum.cpp +++ b/C++/two-sum.cpp @@ -14,4 +14,28 @@ class Solution { } return v; } -}; \ No newline at end of file +}; + +// Above solution is of O(n^2) time complexity + +//O(n) time complexity +//O(n) space complexity + + +vector twoSum(vector &numbers, int target) +{ + //Key is the number and value is its index in the vector. + unordered_map hash; + // make a vector final result + vector finalresult; + for (int i = 0; i < numbers.size(); i++) { + int n = target - numbers[i]; + + //if n is found in map, return them + if (hash.find(n) != hash.end()) { + result.push_back(hash[n] + 1); + result.push_back(i + 1); + return finalresult; + } +} +} diff --git a/C++/xor-operation-in-an-array.cpp b/C++/xor-operation-in-an-array.cpp new file mode 100644 index 00000000..34443c6e --- /dev/null +++ b/C++/xor-operation-in-an-array.cpp @@ -0,0 +1,12 @@ +// difficulty easy +class Solution { +public: + int xorOperation(int n, int start) { + // brute force method + int ans = 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/add-two-numbers.java b/Java/Add-Two-Numbers.java similarity index 100% rename from Java/add-two-numbers.java rename to Java/Add-Two-Numbers.java diff --git a/Java/All_Paths_From_Source_to_Target.java b/Java/All_Paths_From_Source_to_Target.java new file mode 100644 index 00000000..5367ef18 --- /dev/null +++ b/Java/All_Paths_From_Source_to_Target.java @@ -0,0 +1,29 @@ +class Solution { + void findPaths(int[][] graph,int fromNode,List path,List> ans){ + //If fromNode has reached the last Node of graph , add this node to path and return + if(fromNode==graph.length-1) + { + path.add(fromNode); + ans.add(new ArrayList(path)); + path.remove(path.indexOf(fromNode)); + return; + } + //Traverse for all nodes in list of fromNode + for(int i=0;i(); + //Add the node and call for its list of reachable nodes + path.add(fromNode); + findPaths(graph,graph[fromNode][i],path,ans); + path.remove(path.size()-1); + } + return; + } + + public List> allPathsSourceTarget(int[][] graph) { + List> ans=new ArrayList>(); + //Start from 0 node + findPaths(graph,0,new ArrayList(),ans); + return ans; + } +} diff --git a/Java/Arithmetic-Subarrays.java b/Java/Arithmetic-Subarrays.java new file mode 100644 index 00000000..c5fdcca1 --- /dev/null +++ b/Java/Arithmetic-Subarrays.java @@ -0,0 +1,69 @@ +/** + * Problem Name : Arithmetic Subarrays + * Concept Involved : Maths, Interval Count, Array + * + * Execution Time : 500 ms + * Memory Consumed : 40.6 mb + * + * Solution : We have been asked Q queries. Every query has a range l and r + * and we have to tell whether the array elements from l to r form an + * Arithmetic Sequence. + * The idea is to find the maximum and minimum element of the sub array for + * every query and divide the difference of maximum and minimum element into + * (maximum-minimum)/x equal parts, where x is the size of the sub array. + * Now we jump to every part and check whether the given part is present in the + * sub array. For this we can use a hash set, I have used index based hashing + * in the array to save some time. +*/ + +class Solution { + public int getValue(int ele){ + if(ele < 0){ + return 100000 - ele; + } + return ele; + } + public List checkArithmeticSubarrays(int[] nums, int[] l, int[] r) { + int m = l.length; + ArrayList res = new ArrayList<>(); + + for(int i=0; i 0 ? diff : -diff; // absolute + if(diff > 1){ + return false; + } + return isBalanced(root.left) && isBalanced(root.right); + } + } + + private int height(TreeNode root){ + // calculate the height of a tree + if(root == null){ + return 0; + } + else{ + int left = height(root.left); + int right = height(root.right); + int height = left > right ? left : right; + return height + 1; + } + } +} 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/Design-a-Stack-With-Increment-Operation.java b/Java/Design-a-Stack-With-Increment-Operation.java new file mode 100644 index 00000000..a85058e4 --- /dev/null +++ b/Java/Design-a-Stack-With-Increment-Operation.java @@ -0,0 +1,35 @@ +class CustomStack { + int[] stack; + public int top=-1; + public CustomStack(int maxSize) { + stack=new int[maxSize]; + } + + public void push(int x) { + if(toptop+1?top+1:k);i++) { + stack[i]+=val; + } + } +} + +/** + * Your CustomStack object will be instantiated and called as such: + * CustomStack obj = new CustomStack(maxSize); + * obj.push(x); + * int param_2 = obj.pop(); + * obj.increment(k,val); + */ \ No newline at end of file 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/Number-of-Good-Pairs.java b/Java/Number-of-Good-Pairs.java new file mode 100644 index 00000000..bab52529 --- /dev/null +++ b/Java/Number-of-Good-Pairs.java @@ -0,0 +1,14 @@ +class Solution { + public int numIdenticalPairs(int[] nums) { + int numGoodPairs = 0; + + for (int i = 0; i < nums.length; i++) { + for (int j = 0; j < nums.length; j++) { + if (i == j) continue; // cannot check against itself + if (nums[i] == nums[j] && i < j) numGoodPairs++; + } + } + + return numGoodPairs; + } +} 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> permute(int[] nums) { + List> result = new ArrayList<>(); + helper(0, nums, result); + return result; +} + +private void helper(int start, int[] nums, List> result) +{ + if(start==nums.length-1){ + ArrayList list = new ArrayList<>(); //if starting value(say n) is the last value , this will make a new list with the values and the new starting value is n + for(int num: nums) + { + list.add(num); + } + result.add(list); + return; + } + + for(int i=start; i **Problem Link** : [Redundant Connection (LeetCode)](https://leetcode.com/problems/redundant-connection/)
+> **Concepts Involved** : *Tree, Disjoint Union Set* + +## Problem Statement +We have been provided with a list of edges. These edges form a Tree. The list has one extra edge as well. We have to find that extra edge which if removed from the list makes the resulting list of edges a Tree of N nodes. + +## Solution +

+We have been given with a list of edges. Now we need to remove one edge from the List so that the resultant list forms a Tree. Basically a Tree can be termed as a special Graph where every nodes are connected to one another directly or indirectly and there no loops present. As there is only one extra edge, then it must join two nodes which are already connected. And we neeed to find that particular edge. +

+

+The basic idea is to use a Disjoint Union Sets here. We will iterate over the list of edges and for every edge (u,v) we will put u and v in a single set. If during the iteration we find an edge such that both the nodes u and v is in the same set, then we can say that it is an extra edge which can be removed. We can store that as our result and return it after the iteration. +

+ +![Editorial Image](./images/image-1.png) + +

+The basic source code for the problem looks like : + +``` + for each (edge in edge_list) : + if(same_set(edge.u, edge.v)){ + extra_node_u = edge.u + extra_node_v = edge.v + } + else{ + put_in_same_set(edge.u, edge.v) + } + } +``` +

+ +## Complexity + * The solution Time Complexity is : ***O(N)*** + * The solution Space Complexity is : ***O(N)*** + +> **Author's Note** : I would highly encourage readers to learn the Disjoint Set Union data structure before attempting the question from [here](https://www.geeksforgeeks.org/union-find/). diff --git a/Java/Redundant-Connection/images/image-1.png b/Java/Redundant-Connection/images/image-1.png new file mode 100644 index 00000000..840f02d9 Binary files /dev/null and b/Java/Redundant-Connection/images/image-1.png differ diff --git a/Java/Redundant-Connection/redundant-connection.java b/Java/Redundant-Connection/redundant-connection.java new file mode 100644 index 00000000..327d0325 --- /dev/null +++ b/Java/Redundant-Connection/redundant-connection.java @@ -0,0 +1,59 @@ +/** + * Problem Name : Redundant Connection + * Concept Involved : Trees, Union Find + * + * Execution Time : 1 ms + * Memory Consumed : 39 mb +**/ + +class DUS{ + public int[] parent; + public int n; + + DUS(int n){ + this.n = n; + parent = new int[n]; + for(int i=0; i target){ + return false; + } + else if(matrix[i][j] == target){ + return true; + } + else{ + continue; + } + } + } + + return false; + } +} diff --git a/Java/SignOf.java b/Java/SignOf.java new file mode 100644 index 00000000..3077aca4 --- /dev/null +++ b/Java/SignOf.java @@ -0,0 +1,18 @@ + + +// https://leetcode.com/problems/sign-of-the-product-of-an-array/ + + public int arraySign(int[] nums) { + int count = 0; + for(int i : nums){ + if(i == 0){ + return 0; + }else if(i < 0){ + count++; + } + } + if(count % 2 == 0){ + return 1; + } + return -1; + } diff --git a/Java/Sum_of_two_integers.java b/Java/Sum_of_two_integers.java new file mode 100644 index 00000000..4cc648c8 --- /dev/null +++ b/Java/Sum_of_two_integers.java @@ -0,0 +1,15 @@ +// Time-Complexity:- -> 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/Ugly-Number.java b/Java/Ugly-Number.java new file mode 100644 index 00000000..c066d724 --- /dev/null +++ b/Java/Ugly-Number.java @@ -0,0 +1,23 @@ +class Solution { + public boolean isUgly(int num) { + if(num == 0) return false; + if(num == 1) return true; + + if(num % 2 == 0){ + num = num / 2; + return isUgly(num); + } + + if(num % 3 == 0){ + num=num / 3; + return isUgly(num); + } + + if(num % 5 == 0){ + num = num / 5; + return isUgly(num); + } + + return false; + } +} 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/buddy-strings.java b/Java/buddy-strings.java new file mode 100644 index 00000000..a040770d --- /dev/null +++ b/Java/buddy-strings.java @@ -0,0 +1,50 @@ +/** + * Problem Name : Buddy Strings + * Concept Involved : String Manipulation, Frequency Computation, Observation + * + * Execution Time : 2 ms + * Memory Consumed : 39.1 mb + * +*/ +class Solution { + public boolean isDuplicate(String str){ + int[] fre = new int[26]; + for(int i=0; i 1){ + return true; + } + } + return false; + } + public boolean buddyStrings(String A, String B) { + if(A.length() != B.length()){ + return false; + } + + int count = 0; + char ca = 'A'; + char cb = 'A'; + + for(int i=0; i 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/generate-a-string-with-characters-that-have-odd-counts.java b/Java/generate-a-string-with-characters-that-have-odd-counts.java new file mode 100644 index 00000000..0bc0b973 --- /dev/null +++ b/Java/generate-a-string-with-characters-that-have-odd-counts.java @@ -0,0 +1,21 @@ +class Solution { + public String generateTheString(int n) { + String result = ""; + if(n % 2 == 0) { + for(int i = 1; i <= n - 1; i++) { + result = result + 'x'; + } + + result = result + 'y'; + } + else { + for (int i = 1; i <= n; i++) + { + result = result + 'x'; + } + } + + return result; + } + +} \ No newline at end of file diff --git a/Java/graph_connectivity_with_threshold.java b/Java/graph_connectivity_with_threshold.java new file mode 100644 index 00000000..1450ca5a --- /dev/null +++ b/Java/graph_connectivity_with_threshold.java @@ -0,0 +1,66 @@ +/** + * Problem Name : Graph Connectivity with Threshold + * Concept Involved : Disjoint Union Set, Seive + * + * Execution Time : 16 ms + * Memory Consumed : 92.7 mb + * +*/ +class Solution { + public static class Dus { + int[] parent; + int n; + + Dus(int n) { + this.n = n; + parent = new int[n]; + for (int i = 1; i < n; i++) { + parent[i] = i; + } + } + + public int find(int u) { + if (u != parent[u]) { + parent[u] = find(parent[u]); + } + return parent[u]; + } + + public void union(int u, int v) { + int pu = find(u); + int pv = find(v); + + if (pu != pv) { + parent[pv] = pu; + } + } + } + public List areConnected(int n, int threshold, int[][] queries) { + ArrayList res = new ArrayList<>(); + Dus dus = new Dus(n+1); + + for(int i=1; i<=n; i++){ + for(int j=2*i; j<=n; j+=i){ + if(i > threshold){ + dus.union(i,j); + } + } + } + + for(int i=0; i= 1000){//if the number is larger than 1000, then add an M to the roman string and subtract 1000 from number + roman += "M"; + number -= 1000; + } + else if(number >= 900){//if the number is larger than 900, then add an CM to the roman string and subtract 900 from number + roman += "CM"; + number -= 900; + } + else if(number >= 500){//if the number is larger than 500, then add an D to the roman string and subtract 500 from number + roman += "D"; + number -= 500; + } + else if(number >= 400){//if the number is larger than 400, then add an CD to the roman string and subtract 400 from number + roman += "CD"; + number -= 400; + } + else if(number >= 100){//if the number is larger than 100, then add an C to the roman string and subtract 100 from number + roman += "C"; + number -= 100; + } + else if(number >= 90){//if the number is larger than 90, then add an XC to the roman string and subtract 90 from number + roman += "XC"; + number -= 90; + } + else if(number >= 50){//if the number is larger than 50, then add an L to the roman string and subtract 50 from number + roman += "L"; + number -= 50; + } + else if(number >= 40){//if the number is larger than 40, then add an XL to the roman string and subtract 40 from number + roman += "XL"; + number -= 40; + } + else if(number >= 10){//if the number is larger than 10, then add an X to the roman string and subtract 10 from number + roman += "X"; + number -= 10; + } + else if(number >= 9){//if the number is larger than 9, then add an IX to the roman string and subtract 9 from number + roman += "IX"; + number -= 9; + } + else if(number >= 5){//if the number is larger than 5, then add an V to the roman string and subtract 5 from number + roman += "V"; + number -= 5; + } + else if(number >= 4){//if the number is larger than 4, then add an IV to the roman string and subtract 4 from number + roman += "IV"; + number -= 4; + } + else if(number >= 1){//if the number is larger than 1, then add an I to the roman string and subtract 1 from number + roman += "I"; + number -= 1; + } + } + return roman; + } +} \ No newline at end of file diff --git a/Java/intersection-of-two-linked-lists.java b/Java/intersection-of-two-linked-lists.java new file mode 100644 index 00000000..a6985a3b --- /dev/null +++ b/Java/intersection-of-two-linked-lists.java @@ -0,0 +1,63 @@ +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode(int x) { + * val = x; + * next = null; + * } + * } + */ +public class Solution { + public ListNode getIntersectionNode(ListNode headA, ListNode headB) { + + int lenA = getLinkedListLength(headA); + int lenB = getLinkedListLength(headB); + + ListNode head1 = headA; + ListNode head2 = headB; + + if(lenA > lenB){ + int diff = lenA - lenB; + head1 = moveList(diff, head1); + } + else{ + int diff = lenB - lenA; + head2 = moveList(diff, head2); + } + + while(head1 != null){ + if(head1 == head2){ + return head1; + } + else if(head1.next == head2.next){ + return head1.next; + } + head1 = head1.next; + head2 = head2.next; + } + + return null; + } + + public int getLinkedListLength(ListNode head){ + ListNode currentHead = head; + int len = 0; + + while(currentHead != null){ + currentHead = currentHead.next; + len++; + } + + return len; + } + + public ListNode moveList(int difference, ListNode head){ + while(difference != 0){ + head = head.next; + difference--; + } + return head; + } +} diff --git a/Java/max-nesting-depth-parentheses.java b/Java/max-nesting-depth-parentheses.java new file mode 100644 index 00000000..93e4a7bc --- /dev/null +++ b/Java/max-nesting-depth-parentheses.java @@ -0,0 +1,20 @@ +class Solution { + public int maxDepth(String s) { + + int maxDepth = Integer.MIN_VALUE; + int depth = 0; + + for(int i=0; i maxDepth) ? depth : maxDepth; + } + + return maxDepth; + } +} diff --git a/Java/number-complement.java b/Java/number-complement.java new file mode 100644 index 00000000..99d46bd7 --- /dev/null +++ b/Java/number-complement.java @@ -0,0 +1,22 @@ +class Solution { + public int findComplement(int num) { + + int numberOfBits = numberOfBits(num); + + return num ^ ((1 << numberOfBits) - 1); + } + + /** + * Method to find out the total number of bits in a number. + **/ + public static int numberOfBits(int num){ + int countOfBits = 0; + + while(num != 0){ + num = num >> 1; + countOfBits++; + } + + return countOfBits; + } +} diff --git a/Java/palindrome-number.java b/Java/palindrome-number.java new file mode 100644 index 00000000..53332cfb --- /dev/null +++ b/Java/palindrome-number.java @@ -0,0 +1,19 @@ +class Solution { + public boolean isPalindrome(int x) { + String _x = x+""; // integer convert string + String rev = ""; // store reverse + int i = 0; + for(i = _x.length()-1; i>=0; i--){ + rev += _x.charAt(i); + } + + if(_x.compareTo(rev) == 0){ + // correct + return true; + } + else{ + return false; + } + + } +} diff --git a/Java/path-sum.java b/Java/path-sum.java new file mode 100644 index 00000000..526031d6 --- /dev/null +++ b/Java/path-sum.java @@ -0,0 +1,40 @@ +/** + * Definition for a binary tree node. + * public class TreeNode { + * int val; + * TreeNode left; + * TreeNode right; + * TreeNode() {} + * TreeNode(int val) { this.val = val; } + * TreeNode(int val, TreeNode left, TreeNode right) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +class Solution { + public boolean hasPathSum(TreeNode root, int sum) { + if(root == null){ + // exception + return false; + } + if(root.left == null && root.right == null){ + if(sum == root.val){ + return true; + } + return false; + } + else{ + boolean left = false; + boolean right = false; + if(root.left != null){ + left = hasPathSum(root.left, sum-root.val); + } + if(root.right != null){ + right = hasPathSum(root.right, sum-root.val); + } + return left||right; + } + } +} diff --git a/Java/path-with-minimum-effort.java b/Java/path-with-minimum-effort.java new file mode 100644 index 00000000..9c73274f --- /dev/null +++ b/Java/path-with-minimum-effort.java @@ -0,0 +1,90 @@ +/** + * Problem Name : Path with Minimum Effort + * Concept Involved : Graphs, Dijkstra's Shortest Path + * + * Execution Time : 1229 ms + * Memory Consumed : 39.4 mb + * +*/ +class Point{ + int x; + int y; + int height; + + public Point(int x, int y, int height){ + this.x = x; + this.y = y; + this.height = height; + } +} +class Solution { + public int minimumEffortPath(int[][] heights) { + int n = heights.length; + int m = heights[0].length; + + int sx = 0; + int sy = 0; + + int[][] dist = new int[n][m]; + int[][] vis = new int[n][m]; + + for(int i=0; i dist[k][l] && vis[k][l]==0){ + mdist = dist[k][l]; + px = k; + py = l; + } + } + } + + vis[px][py] = 1; + Point cpoint = new Point(px, py, heights[px][py]); + + if(cpoint.x > 0){ + int lx = cpoint.x - 1; + int ly = cpoint.y; + if(vis[lx][ly] == 0){ + dist[lx][ly] = Math.min(dist[lx][ly], Math.max(dist[cpoint.x][cpoint.y], Math.abs(cpoint.height - heights[lx][ly]))); + } + } + if(cpoint.x < n-1){ + int lx = cpoint.x + 1; + int ly = cpoint.y; + if(vis[lx][ly] == 0){ + dist[lx][ly] = Math.min(dist[lx][ly], Math.max(dist[cpoint.x][cpoint.y], Math.abs(cpoint.height - heights[lx][ly]))); + } + } + if(cpoint.y > 0){ + int lx = cpoint.x; + int ly = cpoint.y - 1; + if(vis[lx][ly] == 0){ + dist[lx][ly] = Math.min(dist[lx][ly], Math.max(dist[cpoint.x][cpoint.y], Math.abs(cpoint.height - heights[lx][ly]))); + } + } + if(cpoint.y < m-1){ + int lx = cpoint.x; + int ly = cpoint.y + 1; + if(vis[lx][ly] == 0){ + dist[lx][ly] = Math.min(dist[lx][ly], Math.max(dist[cpoint.x][cpoint.y], Math.abs(cpoint.height - heights[lx][ly]))); + } + } + } + } + + return dist[n-1][m-1]; + } +} \ No newline at end of file diff --git a/Java/roman-to-integer.java b/Java/roman-to-integer.java new file mode 100644 index 00000000..47c12634 --- /dev/null +++ b/Java/roman-to-integer.java @@ -0,0 +1,54 @@ +public class RomanToInteger{ + public static int GetNum(int num) {//gets the number assoicate with a roman character + if (num == 'I' || num == 'i') { + return 1; + } + if (num == 'V' || num == 'v') { + return 5; + } + if (num == 'X' || num == 'x') { + return 10; + } + if (num == 'L' || num == 'l') { + return 50; + } + if (num == 'C' || num == 'c') { + return 100; + } + if (num == 'D' || num == 'd') { + return 500; + } + if (num == 'M' || num == 'm') { + return 1000; + } + + return -1; + } + + public static int romanToNumber(String roman){//Converts a roman numerial into a number + int results = 0; + for (int i = 0; i < roman.length(); i++) {//iterate through all the characters + int cur = GetNum(roman.charAt(i));//Gets the integer of the roman number + if (cur == -1) {//checks if the cur num is -1, if it is -1, it means that it is an invalid character + return -1; + } + if (i + 1 < roman.length()) {//checks if the next index is out of bounds + int next = GetNum(roman.charAt(i + 1));//gets the next character character + if (next == -1) {//checks if the cur num is -1, if it is -1, it means that it is an invalid character + return -1; + } + if (cur >= next) {//compares the current number to the next number + results += cur;//if it is bigger, simply add the current number + } + else {//if the current number is smaller than the next number + results += (next - cur);//subtract the next number by the current number + i++;//increment the index, since the next number has already been used + } + } + else {//only here to add the last number to the results + results += cur;//adds the last character to the results + } + } + return results;//returns the result + } +} \ No newline at end of file diff --git a/Java/set-matrix-zeroes.java b/Java/set-matrix-zeroes.java new file mode 100644 index 00000000..678f0897 --- /dev/null +++ b/Java/set-matrix-zeroes.java @@ -0,0 +1,34 @@ +class Solution { + public void setZeroes(int[][] matrix) { + Boolean isCol = false; + int R = matrix.length, C = matrix[0].length; + for (int i = 0; i < R; i++) { + if (matrix[i][0] == 0) { + isCol = true; + } + for (int j = 1; j < C; j++) { + if (matrix[i][j] == 0) { + matrix[0][j] = 0; + matrix[i][0] = 0; + } + } + } + for (int i = 1; i < R; i++) { + for (int j = 1; j < C; j++) { + if (matrix[i][0] == 0 || matrix[0][j] == 0) { + matrix[i][j] = 0; + } + } + } + if (matrix[0][0] == 0) { + for (int j = 0; j < C; j++) { + matrix[0][j] = 0; + } + } + if (isCol) { + for (int i = 0; i < R; i++) { + matrix[i][0] = 0; + } + } + } +} diff --git a/Java/shuffle-the-array.java b/Java/shuffle-the-array.java new file mode 100644 index 00000000..5496fe75 --- /dev/null +++ b/Java/shuffle-the-array.java @@ -0,0 +1,18 @@ +class Solution { + public int[] shuffle(int[] nums, int n) { + int [] result = new int[2 * n]; + + // Looping over the array + for(int i = 0; i < 2 * n; i ++){ + // If the array index is even + if(i % 2 == 0) + result[i] = nums[i / 2]; + + // If it's not even, its odd + else + result[i] = nums[n + i / 2]; + } + + return result; + } +} \ No newline at end of file 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/Java/valid-sudoku.java b/Java/valid-sudoku.java new file mode 100644 index 00000000..f6b0eea9 --- /dev/null +++ b/Java/valid-sudoku.java @@ -0,0 +1,76 @@ +/** + * Problem Name : Valid Sudoku + * Concept Involved : 2D Array, Frequency Count + * + * Execution Time : 2 ms + * Memory Consumed : 38.8 mb + * + * Solution : We have been given with a Sudoku + * Puzzle, we have to determine whether the puzzle + * is valid or not. + * In order to check the validity every row and column + * of sudoku must have numbers from 0 to 9 and in a non + * repeating fashion and same for in every 3x3 block. + * I have used array based indexing to compute the + * frequency of elements in every rows, columns and blocks + * and checking its validity afterwards. + * If every check is passed then we return True at the end. +*/ +class Solution { + public boolean isValid(ArrayList arr){ + int[] fre = new int[10]; + for(int ele : arr){ + fre[ele]++; + if(fre[ele] > 1){ + return false; + } + } + return true; + } + public boolean isValidSudoku(char[][] board) { + for(int i=0; i<9; i++){ + ArrayList row = new ArrayList<>(); + for(int j=0; j<9; j++){ + if(board[i][j] != '.'){ + int num = board[i][j] - '0'; + row.add(num); + } + } + if(!isValid(row)){ + return false; + } + } + + for(int i=0; i<9; i++){ + ArrayList col = new ArrayList<>(); + for(int j=0; j<9; j++){ + if(board[j][i] != '.'){ + int num = board[j][i] - '0'; + col.add(num); + } + } + if(!isValid(col)){ + return false; + } + } + + for(int i=0; i<9; i+=3){ + for(int j=0; j<9; j+=3){ + ArrayList block = new ArrayList<>(); + for(int k=i;k wordList) { + HashSet hs=new HashSet<>(wordList); + if(!hs.contains(endWord)) + { + return 0; + } + int steps=1; + Queue q=new LinkedList<>(); + q.add(beginWord); + while(!q.isEmpty()) + { + int count=q.size(); + for(int i=0;i { + let current = root; + let right; + let left; + if(!current) { + return null; + // this checks if the current node is a leaf node + } if (!current.right && !current.left) { + return depth; + } + right = traversal(current.right, depth+1) + left = traversal(current.left, depth+1) + if(!right) { + return left; + } else if(!left) { + return right; + } else { + if(right < left) { + return right + } else { + return left + } + } +} \ No newline at end of file diff --git a/JavaScript/146.LRU-Cache.js b/JavaScript/146.LRU-Cache.js new file mode 100644 index 00000000..98fc220d --- /dev/null +++ b/JavaScript/146.LRU-Cache.js @@ -0,0 +1,91 @@ +/** + * Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. + +Implement the LRUCache class: + +LRUCache(int capacity) Initialize the LRU cache with positive size capacity. +int get(int key) Return the value of the key if the key exists, otherwise return -1. +void put(int key, int value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key. +Follow up: +Could you do get and put in O(1) time complexity? + + + +Example 1: + +Input +["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"] +[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]] +Output +[null, null, null, 1, null, -1, null, -1, 3, 4] + +Explanation +LRUCache lRUCache = new LRUCache(2); +lRUCache.put(1, 1); // cache is {1=1} +lRUCache.put(2, 2); // cache is {1=1, 2=2} +lRUCache.get(1); // return 1 +lRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3} +lRUCache.get(2); // returns -1 (not found) +lRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3} +lRUCache.get(1); // return -1 (not found) +lRUCache.get(3); // return 3 +lRUCache.get(4); // return 4 + + +Constraints: + +1 <= capacity <= 3000 +0 <= key <= 3000 +0 <= value <= 104 +At most 3 * 104 calls will be made to get and put. + */ + +/** + * @param {number} capacity + */ +var LRUCache = function (capacity) { + this.cache = new Map(); + this.capacity = capacity; +}; + +/** + * @param {number} key + * @return {number} + */ +LRUCache.prototype.get = function (key) { + if (!this.cache.has(key)) { + return -1; + } + const value = this.cache.get(key); + this.cache.delete(key); + this.cache.set(key, value); + return value; +}; + +/** + * @param {number} key + * @param {number} value + * @return {void} + */ +LRUCache.prototype.put = function (key, value) { + if (this.capacity <= 0) { + return; + } + if (this.cache.has(key)) { + this.cache.delete(key); + this.cache.set(key, value); + return; + } + if (this.cache.size >= this.capacity) { + const removedKey = this.cache.keys().next().value; + this.cache.delete(removedKey); + } + this.cache.set(key, value); +}; + +/** + * Your LRUCache object will be instantiated and called as such: + * var obj = new LRUCache(capacity) + * var param_1 = obj.get(key) + * obj.put(key,value) + */ diff --git a/JavaScript/152.Maximum-Product-Subarray.js b/JavaScript/152.Maximum-Product-Subarray.js new file mode 100644 index 00000000..32800d3c --- /dev/null +++ b/JavaScript/152.Maximum-Product-Subarray.js @@ -0,0 +1,37 @@ +/** + * Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product. + +Example 1: + +Input: [2,3,-2,4] +Output: 6 +Explanation: [2,3] has the largest product 6. +Example 2: + +Input: [-2,0,-1] +Output: 0 +Explanation: The result cannot be 2, because [-2,-1] is not a subarray. + */ + +/** + * @param {number[]} nums + * @return {number} + */ +var maxProduct = function (nums) { + if (!nums.length) return 0; + let maxEnding = nums[0]; + let minEnding = nums[0]; + let res = nums[0]; + for (let i = 1; i < nums.length; i++) { + if (nums[i] < 0) { + let temp = minEnding; + minEnding = maxEnding; + maxEnding = temp; + } + + maxEnding = Math.max(maxEnding * nums[i], nums[i]); + minEnding = Math.min(minEnding * nums[i], nums[i]); + res = Math.max(res, maxEnding); + } + return res; +}; diff --git a/JavaScript/5.Longest-Palindromic-Substring.js b/JavaScript/5.Longest-Palindromic-Substring.js new file mode 100644 index 00000000..f1c605eb --- /dev/null +++ b/JavaScript/5.Longest-Palindromic-Substring.js @@ -0,0 +1,54 @@ +/** + * Given a string s, return the longest palindromic substring in s. + * + * Example 1: + +Input: s = "babad" +Output: "bab" +Note: "aba" is also a valid answer. +Example 2: + +Input: s = "cbbd" +Output: "bb" +Example 3: + +Input: s = "a" +Output: "a" +Example 4: + +Input: s = "ac" +Output: "a" + + +Constraints: + +1 <= s.length <= 1000 +s consist of only digits and English letters (lower-case and/or upper-case), + */ + +/** + * @param {string} s + * @return {string} + */ +var longestPalindrome = function (s) { + var max = 0; + var head = 0; + var n = s.length; + var i = 0; + while (i < n - max / 2) { + var lo = i; + while (i < n && s[i] === s[lo]) { + i++; + } + var hi = i - 1; + while (lo >= 0 && hi < n && s[lo] === s[hi]) { + lo--; + hi++; + } + if (hi - lo - 1 > max) { + max = hi - lo - 1; + head = lo + 1; + } + } + return s.slice(head, head + max); +}; diff --git a/JavaScript/98.Validate-Binary-Search-Tree.js b/JavaScript/98.Validate-Binary-Search-Tree.js new file mode 100644 index 00000000..b1c6f8dd --- /dev/null +++ b/JavaScript/98.Validate-Binary-Search-Tree.js @@ -0,0 +1,52 @@ +/** + * + * Given a binary tree, determine if it is a valid binary search tree (BST). + * + * Assume a 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: + + 2 + / \ + 1 3 + +Input: [2,1,3] +Output: true +Example 2: + + 5 + / \ + 1 4 + / \ + 3 6 + +Input: [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. + */ + +var isValidBST = function ( + root, + lower = Number.MIN_SAFE_INTEGER, + upper = Number.MAX_SAFE_INTEGER +) { + if (!root) return true; + + let value = root.val; + if (value <= lower || value >= upper) { + return false; + } + + if (!isValidBST(root.right, value, upper)) { + return false; + } + + if (!isValidBST(root.left, lower, value)) { + return false; + } + return true; +}; 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/496_nextgreaterelement.py b/Python/496_nextgreaterelement.py new file mode 100644 index 00000000..73faac76 --- /dev/null +++ b/Python/496_nextgreaterelement.py @@ -0,0 +1,10 @@ +class Solution: + def check(self, number, nums1, nums2): + index = nums2.index(number) + for _ in range(index, len(nums2)): + if(nums2[_]>number): + return nums2[_] + return -1 + + def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: + return [self.check(x, nums1, nums2) for x in nums1] diff --git a/Python/621-Task-Scheduler.py b/Python/621-Task-Scheduler.py new file mode 100644 index 00000000..730585af --- /dev/null +++ b/Python/621-Task-Scheduler.py @@ -0,0 +1,32 @@ +""" +Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. +Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, +the CPU could complete either one task or just be idle. + +However, there is a non-negative integer n that represents the cooldown period between +two same tasks (the same letter in the array), +is that there must be at least n units of time between any two same tasks. + + +Memory ->14.4MB +runtime ->412ms + + + + +""" + + +class Solution: + def leastInterval(self, tasks: List[str], n: int) -> int: + counter=Counter(tasks) + freq=sorted(list(counter.values())) + + max_idle=freq.pop() + total=(max_idle-1)*n + + while freq and total>0: + total=total-min(max_idle-1,freq.pop()) + + total=max(0,total) + return len(tasks) + total diff --git a/Python/622-Design-Circular-Queue.py b/Python/622-Design-Circular-Queue.py new file mode 100644 index 00000000..69ab4ad4 --- /dev/null +++ b/Python/622-Design-Circular-Queue.py @@ -0,0 +1,80 @@ +""" +Design your implementation of the circular queue. The circular queue is a linear data structure +in which the operations are performed based on FIFO (First In First Out) principle +and the last position is connected back to the first position to make a circle. It is also called "Ring Buffer". + +One of the benefits of the circular queue is that we can make use of the spaces in front of the queue. +In a normal queue, once the queue becomes full, we cannot insert the next element +even if there is a space in front of the queue. But using the circular queue, we can use the space to store new values. + +link - https://leetcode.com/problems/design-circular-queue/ + +runtime - 72ms +memory - 14.6 mb + +time complexity - O(n) +space complexity - O(n) + +""" + + + +class MyCircularQueue: + + def __init__(self, k: int): + """ + Initialize your data structure here. Set the size of the queue to be k. + """ + self.queue = [None] *k + self.head = 0 + self.tail = -1 + self.size = 0 + self.max_size = k + + + def enQueue(self, value: int) -> bool: + """ + Insert an element into the circular queue. Return true if the operation is successful. + """ + if self.isFull(): + return False + self.tail = (self.tail +1) % self.max_size + self.queue[self.tail] = value + self.size += 1 + return True + + def deQueue(self) -> bool: + """ + Delete an element from the circular queue. Return true if the operation is successful. + """ + if self.isEmpty(): + return False + self.queue[self.head] = None + self.head = (self.head +1) % self.max_size + self.size -= 1 + return True + + def Front(self) -> int: + """ + Get the front item from the queue. + """ + return -1 if self.isEmpty() else self.queue[self.head] + + def Rear(self) -> int: + """ + Get the last item from the queue. + """ + return -1 if self.isEmpty() else self.queue[self.tail] + + def isEmpty(self) -> bool: + """ + Checks whether the circular queue is empty or not. + """ + return self.size == 0 + + + def isFull(self) -> bool: + """ + Checks whether the circular queue is full or not. + """ + return self.size == self.max_size diff --git a/Python/994_Rotting_Oranges.py b/Python/994_Rotting_Oranges.py new file mode 100644 index 00000000..7c1fab0c --- /dev/null +++ b/Python/994_Rotting_Oranges.py @@ -0,0 +1,47 @@ +# Time Complexity = O(rows*columns) +# Space Complexity = O(rows*columns) + +class Solution: + def orangesRotting(self, grid: List[List[int]]) -> int: + n = len(grid) + m = len(grid[0]) + + count = 0 + rotten = [] + for i in range(n): + for j in range(m): + if grid[i][j]==2: + rotten.append((i,j)) + count+=1 + elif grid[i][j] == 1: + count+=1 + + + if count == 0: + return 0 + + cycles = 0 + + while rotten: + count-=len(rotten) + newRotten = [] + for i,j in rotten: + self.destroy(grid,i+1,j,n,m,newRotten) + self.destroy(grid,i-1,j,n,m,newRotten) + self.destroy(grid,i,j+1,n,m,newRotten) + self.destroy(grid,i,j-1,n,m,newRotten) + rotten = newRotten + cycles+=1 + + if count>0: + return -1 + else: + return cycles-1 + + def destroy(self, grid, i, j, n, m, rotten): + if 0<=i List[int]: + if not root: + return [] + result = [] + stack = [] + node = root + while stack or node: + while node: + stack.append(node) + node = node.left + node = stack.pop() + result.append(node.val) + node = node.right + return result + + diff --git a/Python/LRUCache.py b/Python/LRUCache.py new file mode 100644 index 00000000..0955142b --- /dev/null +++ b/Python/LRUCache.py @@ -0,0 +1,69 @@ +class ListNode(object): + def __init__(self,key,val): + self.key = key + self.value = val + self.next = None + self.prev = None + +class LRUCache: + + def __init__(self, capacity: int): + self.cap = capacity + self.dic = {} + self.head = ListNode(-1,-1) + self.tail = ListNode(-1,-1) + self.head.next = self.tail + self.tail.prev = self.head + + + def get(self, key: int) -> int: + if key in self.dic: + node = self.dic[key] + self.remove(node) + self.add(node) + return node.value + return -1 + + def put(self, key: int, value: int) -> None: + + if key in self.dic: + node = self.dic[key] + self.remove(node) + del self.dic[node.key] + if len(self.dic)>=self.cap: + node = self.head.next + self.remove(node) + del self.dic[node.key] + + node = ListNode(key,value) + self.dic[key] = node + self.add(node) + # self.show(self.head) + + + + def remove(self,node): + prevNode = node.prev + prevNode.next = node.next + node.next.prev = prevNode + + def add(self,node): + tailprev = self.tail.prev + tailprev.next = node + node.prev = tailprev + node.next = self.tail + self.tail.prev = node + # self.show(self.head) + + def show(self,head): + while head: + print(head.value,end=" ") + head = head.next + print() + + + +# Your LRUCache object will be instantiated and called as such: +# obj = LRUCache(capacity) +# param_1 = obj.get(key) +# obj.put(key,value) 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/binary-tree-inorder-traversal.py b/Python/binary-tree-inorder-traversal.py new file mode 100644 index 00000000..d850aea7 --- /dev/null +++ b/Python/binary-tree-inorder-traversal.py @@ -0,0 +1,17 @@ +#Time Complexity: O(n) +#Space Complexity: O(n) +#Speed: 78.92% +#Memory: 99.97% + +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def inorderTraversal(self, root: TreeNode) -> List[int]: + if root is None: + return [] + else: + return self.inorderTraversal(root.left) + [root.val] + self.inorderTraversal(root.right) diff --git a/Python/group_anagram.py b/Python/group_anagram.py new file mode 100644 index 00000000..dea97e8e --- /dev/null +++ b/Python/group_anagram.py @@ -0,0 +1,28 @@ +''' +Given an array of strings strs, group the anagrams together. You can return the answer in any order. + +An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. + +Example: +Input: strs = ["eat","tea","tan","ate","nat","bat"] +Output: [["bat"],["nat","tan"],["ate","eat","tea"]] +''' + +class Solution(object): + def groupAnagrams(self, strs): + """ + :type strs: List[str] + :rtype: List[List[str]] + """ + from collections import defaultdict + + anagrams = defaultdict(list) + for s in strs: + anagrams[str(sorted(s))].append(s) + + return list(anagrams.values()) + +n=["eat", "tea", "tan", "ate", "nat", "bat"] +ans=Solution() +res=ans.groupAnagrams(n) +print(res) 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/Python/longest-valid-parentheses.py b/Python/longest-valid-parentheses.py new file mode 100644 index 00000000..78f06ac9 --- /dev/null +++ b/Python/longest-valid-parentheses.py @@ -0,0 +1,20 @@ +''' +Speed: 95.97% +Memory: 24.96% +Time complexity: O(n) +Space complexity: O(n) +''' +class Solution(object): + def longestValidParentheses(self, s): + ans=0 + stack=[-1] + for i in range(len(s)): + if(s[i]=='('): + stack.append(i) + else: + stack.pop() + if(len(stack)==0): + stack.append(i) + else: + ans=max(ans,i-stack[-1]) + return ans \ No newline at end of file diff --git a/Python/maximum-depth-of-binary-tree.py b/Python/maximum-depth-of-binary-tree.py new file mode 100644 index 00000000..546ce933 --- /dev/null +++ b/Python/maximum-depth-of-binary-tree.py @@ -0,0 +1,17 @@ +#Time Complexity: O(n) +#Space Complexity: O(n) +#Speed: 98.14% +#Memory: 50.93% + +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def maxDepth(self, root: TreeNode) -> int: + if root is None: + return 0 + else: + return max(self.maxDepth(root.left)+1, self.maxDepth(root.right)+1) \ No newline at end of file diff --git a/Python/reorganize-string.py b/Python/reorganize-string.py new file mode 100644 index 00000000..78450197 --- /dev/null +++ b/Python/reorganize-string.py @@ -0,0 +1,26 @@ +''' +speed: 89.11% +memory: 21:02% +N = len(S), A = 1~26(size of diff alpabet) +ex) aab, N=3, A=2 +time complexity: O(A * (N + logA)) +space complexity: O(N) +''' +class Solution: + def reorganizeString(self, S: str) -> str: + n = len(S) + a= [] + + for c,x in sorted((S.count(x), x) for x in set(S)): + if c > (n+1)/2: # not possible + return '' + a.extend(c*x) + + # empty list + ans = [None] * n + + # placing letters to make possible result + ans[::2], ans[1::2] = a[n//2:], a[:n//2] + return "".join(ans) + + \ No newline at end of file diff --git a/Python/rotate-array.py b/Python/rotate-array.py new file mode 100644 index 00000000..1ad93b26 --- /dev/null +++ b/Python/rotate-array.py @@ -0,0 +1,12 @@ +class Solution: + def rotate(self, nums: List[int], k: int) -> None: + """ + Do not return anything, modify nums in-place instead. + """ + lenz = len(nums) + k = k % lenz + if k == 0: + return nums + nums += nums[:-k] + del nums[:lenz-k] + \ No newline at end of file diff --git a/Python/single-number-ii.py b/Python/single-number-ii.py new file mode 100644 index 00000000..3e4e4738 --- /dev/null +++ b/Python/single-number-ii.py @@ -0,0 +1,22 @@ +class Solution: + def singleNumber(self, nums: List[int]) -> int: + dict1 = {} # Create hashtable + # Add counts into the hashtable + for x in nums: + if x not in dict1: + dict1[x] = 1 + else: + dict1[x] += 1 + # Select the single element + for ans, y in dict1.items(): + if y == 1: + return ans + +# Or bitwise way +class Solution: + def singleNumber(self, nums: List[int]) -> int: + a, b = 0, 0 + # Just bitwise operation, (notx and a and notb) or (x and nota and b) ... + for x in nums: + a, b = (~x&a&~b)|(x&~a&b), ~a&(x^b) + return b \ No newline at end of file diff --git a/README.md b/README.md index ed18e92a..85accc7c 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,23 @@ -# [LeetCode-Solutions](https://www.youtube.com/c/codedecks/) +# [LeetCode-Solutions](https://www.youtube.com/playlist?list=PLlUdLC2oSxz2Y1g6V8oRCzauOvbnKl2Ee) + +

+

Join Us on Telegram & Facebook

+ + + + + + + + + +

LOC Stars Badge 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) + + @@ -12,16 +26,16 @@ ![Language](https://img.shields.io/badge/language-Python%20%2F%20Java%20%2F%20JS%20%2F%20C++-orange.svg)  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)  [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/esta/issues) -[![Discord](https://img.shields.io/discord/463752820026376202.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/Suj9dq) +[![Discord](https://img.shields.io/discord/463752820026376202.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/umYVGnvvAg) [![first-timers-only-friendly](http://img.shields.io/badge/first--timers--only-friendly-blue.svg?style=flat-square)](https://code.publiclab.org#r=all) -[![HitCount](http://hits.dwyl.io/GouravRusiya30/SpringBootRestAPI.svg)](http://hits.dwyl.io/GouravRusiya30/SpringBootRestAPI) -### 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. @@ -29,10 +43,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pull/3) -- There are new LeetCode questions every week. I'll keep updating for full summary and better solutions. -- For more challenging problem solutions, you can also see our [HackerRank-Solutions](https://github.com/codedecks-in/HackerRank-Solutions), [ProjectEuler](https://github.com/codedecks-in/ProjectEuler-Solutions) repositories. -- Hope you enjoy the journey of learning data structures and algorithms. -- Notes: "🔒" means your subscription of [LeetCode premium membership](https://leetcode.com/subscribe/) is required for reading the question. +- There are new LeetCode questions every week. I'll keep updating for full summary and better solutions. +- For more challenging problem solutions, you can also see our [HackerRank-Solutions](https://github.com/codedecks-in/HackerRank-Solutions), [ProjectEuler](https://github.com/codedecks-in/ProjectEuler-Solutions) repositories. +- Hope you enjoy the journey of learning data structures and algorithms. +- Notes: "🔒" means your subscription of [LeetCode premium membership](https://leetcode.com/subscribe/) is required for reading the question. ### Don't forget to give us a 🌟 to support us. @@ -40,39 +54,43 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Algorithms -- [Bit Manipulation](#bit-manipulation) -- [Array](#array) -- [String](#string) -- [Linked List](#linked-list) -- [Stack](#stack) -- [Queue](#queue) -- [Heap](#heap) -- [Tree](#tree) -- [Hash Table](#hash-table) -- [Math](#math) -- [Two Pointers](#two-pointers) -- [Sort](#sort) -- [Recursion](#recursion) -- [Binary Search](#binary-search) -- [Binary Search Tree](#binary-search-tree) -- [Breadth-First Search](#breadth-first-search) -- [Depth-First Search](#depth-first-search) -- [Backtracking](#backtracking) -- [Dynamic Programming](#dynamic-programming) -- [Greedy](#greedy) -- [Graph](#graph) -- [Geometry](#geometry) -- [Simulation](#simulation) -- [Design](#design) -- [Concurrency](#concurrency) +- [Bit Manipulation](#bit-manipulation) +- [Array](#array) +- [String](#string) +- [Linked List](#linked-list) +- [Stack](#stack) +- [Queue](#queue) +- [Heap](#heap) +- [Tree](#tree) +- [Hash Table](#hash-table) +- [Math](#math) +- [Two Pointers](#two-pointers) +- [Sort](#sort) +- [Recursion](#recursion) +- [Binary Search](#binary-search) +- [Binary Search Tree](#binary-search-tree) +- [Breadth-First Search](#breadth-first-search) +- [Depth-First Search](#depth-first-search) +- [Backtracking](#backtracking) +- [Dynamic Programming](#dynamic-programming) +- [Greedy](#greedy) +- [Graph](#graph) +- [Geometry](#geometry) +- [Simulation](#simulation) +- [Design](#design) +- [Concurrency](#concurrency) # Bit Manipulation -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------- | -| 0136 | [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 | -| 0260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | -| 0520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py) | _O(n)_ | _O(1)_ | Easy | | | +| # | 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)
[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 |

@@ -80,33 +98,60 @@ 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 | | | + +
+ +
+ # Array -| # | Title | Solution | Time | Space | Difficulty | Note | Video Explaination | -| --- | ---------------------------------------------------------------------- | ---------------------------------------------- | ---------- | ------ | ---------- | --------- | ---- | -| 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 | | -| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros/) | [JavaScript](./JavaScript/Duplicate-Zeroes.js) | _O(n)_ | _O(n)_ | Easy | Array | | -| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/) | [Java](./Java/can-make-arithmetic-progression-from-sequence.java) | _O(n)_ | _O(1)_ | Easy | Array | | -| 122 | [Best Time to buy and sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [Python](./Python/best-time-to-buy-and-sell-stock-ii.py)
[C++](./C++/Best-Time-to-Buy-and-Sell-Stock-II.cpp) | _O(N)_ | _O(1)_ | Medium | Stocks | | -| 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| | -| 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 | | | -| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/) | [Javascript](./JavaScript/Subdomain-Visit-Count.js) | _O(N*M)_ | _O(N*M + N)_ | Easy | | | -| 53 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | [C++](./C++/maximum-subarray.cpp) | _O(N)_ | _O(1)_ |Easy | Array | | -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [C++](./C++/two-sum.cpp) | _O(N^2)_ | _O(1)_ |Easy | Array | | -| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking) | [C++](./C++/teemo-attacking.cpp) | _O(n)_ | _O(1)_ | Medium| Array | | -| 15 | [3 Sum](https://leetcode.com/problems/3sum/) | [Python](./Python/ThreeNumbersSum.py) | O( nLog(n) ) | O(1) | Medium | Array | -| 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference/) | [Python](./python/SmallestDifference.py) | O(n) | O(1) | Easy | Array | -| 532 | [K-diff Pairs in an Array](https://leetcode.com/problems/k-diff-pairs-in-an-array/) | [C++](./C++/k-diff-pairs-in-an-array.cpp) | O(n) | O(n) | Medium | Array | +| # | 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 | | +| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros/) | [JavaScript](./JavaScript/Duplicate-Zeroes.js) | _O(n)_ | _O(n)_ | Easy | Array | | +| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/) | [Java](./Java/can-make-arithmetic-progression-from-sequence.java) | _O(n)_ | _O(1)_ | Easy | Array | | +| 122 | [Best Time to buy and sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [Python](./Python/best-time-to-buy-and-sell-stock-ii.py)
[C++](./C++/Best-Time-to-Buy-and-Sell-Stock-II.cpp) | _O(N)_ | _O(1)_ | Medium | Stocks | | +| 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)
[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 | | | +| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/) | [Javascript](./JavaScript/Subdomain-Visit-Count.js) | _O(N\*M)_ | _O(N\*M + N)_ | Easy | | | +| 53 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | [C++](./C++/maximum-subarray.cpp) | _O(N)_ | _O(1)_ | Easy | Array | | +| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking) | [C++](./C++/teemo-attacking.cpp) | _O(n)_ | _O(1)_ | Medium | Array | | +| 15 | [3 Sum](https://leetcode.com/problems/3sum/) | [Python](./Python/ThreeNumbersSum.py) | O( nLog(n) ) | O(1) | Medium | Array | +| 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference/) | [Python](./python/SmallestDifference.py) | O(n) | O(1) | Easy | Array | +| 532 | [K-diff Pairs in an Array](https://leetcode.com/problems/k-diff-pairs-in-an-array/) | [C++](./C++/k-diff-pairs-in-an-array.cpp) | O(n) | O(n) | Medium | Array | +| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/) | [Javascript](./JavaScript/152.Maximum-Product-Subarray.js) | O(n) | O(n) | Medium | Array | +| 073 | [Set-Matrix-Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | [Java](./Java/set-matrix-zeroes.java) | O(MN) | O(1) | Medium | Array | +| 1288 | [Remove-Covered-Intervals](https://leetcode.com/problems/remove-covered-intervals) | [C++](./C++/Remove-Covered-Intervals.cpp) | O(N\*N) | O(1) | Medium | Array | +| 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 | +| 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 | +| 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 |
+ @@ -114,14 +159,20 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # String -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | ------ | ------ | ---------- | --- | --------------- | -| 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 | | | -| 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 | | | - +| # | 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 | +| 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 | | | +| 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 | | | +| 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 @@ -130,15 +181,20 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Linked List -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| --- | --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ------ | ------ | ---------- | ------------------ | ---- | -| 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 | | -| 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) | _O(1)_ | _O(k)_ | Medium | Hash Map | | -| 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 | +
@@ -148,10 +204,36 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Stack -| # | 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 | | -| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) | _O(n)_ | _O(1)_ | Medium | Stack | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| ---- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ------ | ------ | ---------- | ---------------------- | ---- | +| 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)
[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 | | +| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder/) | [C++](./C++/Crawler-Log-Folder.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | +| 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 | | + +
+ +
+ +# Queue + +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| --- | ------------------------------------------------------------------------------- | ------------------------------------------------ | ------ | ------ | ---------- | --------------------- | ---- | +| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls/) | [C++](./C++/Number-of-Recent-Calls.cpp) | _O(1)_ | _O(1)_ | Easy | Queue, Sliding Window | +| 641 | [Design Circular Deque](https://leetcode.com/problems/design-circular-deque/) | [Java](./Java/design-circular-deque.java/) | _O(n)_ | _O(n)_ | Medium | Queue, Design | +| 621 | [Task Scheduler ](https://leetcode.com/problems/task-scheduler/) | [Python](./Python/621-Task-Scheduler.py/) | _O(n)_ | _O(n)_ | Medium | Queue | +| 622 | [Design Circular Queue](https://leetcode.com/problems/design-circular-queue/) | [Python](./Python/622-Design-Circular-Queue.py/) | _O(n)_ | _O(n)_ | Medium | Queue |
@@ -161,32 +243,23 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Tree -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | --------- | --------- | ---------- | ---------------------------------------------- | ---- | -| 094 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Java](./Java/binary-tree-inorder-traversal.java) | _O(n)_ | _O(logn)_ | Medium | Binary Tree, Stack, HashTable | | -| 100 | [Same Tree](https://leetcode.com/problems/same-tree/) | [Python](./Python/100.SymmetricTree.py) | _O(n)_ | _O(n)_ | Easy | Tree, Depth-first Search | | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [Java](./Java/symmetric-tree.java)
[Python](./Python/101.SymmetricTree.py) | _O(n)_ | _O(n)_ | Easy | Tree, Breadth-first Search, Depth-first Search | | -| 144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/) | [Java](./Java/binary-tree-preorder-traversal.java) | _O(n)_ | _O(logn)_ | Medium | Binary Tree, Stack | | -| 145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/) | [Java](./Java/binary-tree-postorder-traversal.java) | _O(n)_ | _O(logn)_ | Hard | Binary Tree, Stack | | -| 103 | [ZigZag Level Order](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/) | [JavaScript](./JavaScript/Binary-Tree-ZigZag-Traversal.js) | _O(n)_ | _O(n)_ | Medium | Binary Tree | | -| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/) | [Java](./Java/sum-root-to-leaf-numbers.java) | _O(n)_ | _O(logn)_ | Medium | Binary Tree, Depth First Search | | -| 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/) | [Java](./Java/Range-Sum-Query-Mutable.java) | _O(logn)_ | _O(n)_ | Medium | Segment Tree | | -| 919 | [Complete Binary Tree Inserter](https://leetcode.com/problems/complete-binary-tree-inserter/) | [Java](./Java/complete-binary-tree-inserter.java) | _O(n)_ | _O(n)_ | Medium | Tree | | -| 124 | [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum/) | [C++](./C++/Binary-Tree-Maximum-Path-Sum.cpp) | _O(n)_ | _O(n)_ | Hard | Tree | | -| 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 | | - -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| --- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | --------- | --------- | ---------- | ---------------------------------------------- | ---- | -| 094 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Java](./Java/binary-tree-inorder-traversal.java) | _O(n)_ | _O(logn)_ | Medium | Binary Tree, Stack, HashTable | | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [Java](./Java/symmetric-tree.java) | _O(n)_ | _O(n)_ | Easy | Tree, Breadth-first Search, Depth-first Search | | -| 144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/) | [Java](./Java/binary-tree-preorder-traversal.java) | _O(n)_ | _O(logn)_ | Medium | Binary Tree, Stack | | -| 145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/) | [Java](./Java/binary-tree-postorder-traversal.java) | _O(n)_ | _O(logn)_ | Hard | Binary Tree, Stack | | -| 103 | [ZigZag Level Order](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/) | [JavaScript](./JavaScript/Binary-Tree-ZigZag-Traversal.js) | _O(n)_ | _O(n)_ | Medium | Binary Tree | | -| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/) | [Java](./Java/sum-root-to-leaf-numbers.java) | _O(n)_ | _O(logn)_ | Medium | Binary Tree, Depth First Search | | -| 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/) | [Java](./Java/Range-Sum-Query-Mutable.java) | _O(logn)_ | _O(n)_ | Medium | Segment Tree | | -| 919 | [Complete Binary Tree Inserter](https://leetcode.com/problems/complete-binary-tree-inserter/) | [Java](./Java/complete-binary-tree-inserter.java) | _O(n)_ | _O(n)_ | Medium | Tree -| 103 | [Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/) | [C++](./C++/binary-tree-preorder-traversal.java) | _O(n)_ | _O(n)_ | Medium | Binary Tree, Stack -| 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 +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| ---- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ----------- | ----------- | ---------- | ---------------------------------------------- | ---- | +| 094 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Java](./Java/binary-tree-inorder-traversal.java)
[Python](./Python/Iterative-Inorder-tree-traversal) | _O(n)_ | _O(logn)_ | Medium | Binary Tree, Stack, HashTable | | +| 100 | [Same Tree](https://leetcode.com/problems/same-tree/) | [Python](./Python/100.SymmetricTree.py)
[Java](./Java/Same-Tree.java) | _O(n)_ | _O(n)_ | Easy | Tree, Depth-first Search | | +| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [Java](./Java/symmetric-tree.java)
[Python](./Python/101.SymmetricTree.py) | _O(n)_ | _O(n)_ | Easy | Tree, Breadth-first Search, Depth-first Search | | +| 144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/) | [Java](./Java/binary-tree-preorder-traversal.java) | _O(n)_ | _O(logn)_ | Medium | Binary Tree, Stack | | +| 145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/) | [Java](./Java/binary-tree-postorder-traversal.java) | _O(n)_ | _O(logn)_ | Hard | Binary Tree, Stack | | +| 103 | [ZigZag Level Order](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/) | [JavaScript](./JavaScript/Binary-Tree-ZigZag-Traversal.js)
[C++](./C++/binary-tree-preorder-traversal.java) | _O(n)_ | _O(n)_ | Medium | Binary Tree | | +| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/) | [Java](./Java/sum-root-to-leaf-numbers.java) | _O(n)_ | _O(logn)_ | Medium | Binary Tree, Depth First Search | | +| 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/) | [Java](./Java/Range-Sum-Query-Mutable.java) | _O(logn)_ | _O(n)_ | Medium | Segment Tree | | +| 919 | [Complete Binary Tree Inserter](https://leetcode.com/problems/complete-binary-tree-inserter/) | [Java](./Java/complete-binary-tree-inserter.java) | _O(n)_ | _O(n)_ | Medium | Tree | | +| 124 | [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum/) | [C++](./C++/Binary-Tree-Maximum-Path-Sum.cpp) | _O(n)_ | _O(n)_ | Hard | Tree | | +| 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 | +| 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 | |
@@ -196,14 +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) | _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 | | +| # | 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 | |
@@ -211,12 +287,17 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu

-# Two Pointer +# Two Pointers + +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| --- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ---------------------- | ------------------ | ---------- | ----------- | ---------------- | +| 005 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | [Python](./Python/5_LongestPalindromicSubstring.py)
[JavaScript](./JavaScript/5.Longest-Palindromic-Substring.js) | _O(N^2)_
_O(N^2)_ | _O(N)_
_O(1)_ | Medium | | Expand the Wings | +| 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 | | + -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| --- | --------------------------------------------------------------------------------------------- | --------------------------------------------------- | -------- | ------ | ---------- | --- | ---------------- | -| 005 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | [Python](./Python/5_LongestPalindromicSubstring.py) | _O(N^2)_ | _O(N)_ | Medium | | Expand the Wings | -| 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 | | |
⬆️ Back to Top @@ -225,15 +306,25 @@ 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) | _O(n)_ | _O(1)_ | Medium | Math | | -| 050 | [Pow(x, n)](https://leetcode.com/problems/powx-n/) | [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 | | -| 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 | | +| # | 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 | | +
⬆️ Back to Top @@ -246,7 +337,13 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ------------------------- | ----------------- | ---------- | --- | ---- | | 1284 | [Minimum Number of Flips to Convert Binary Matrix to Zero Matrix](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix/) | [C++](./C++/Minimum-Number-of-Flips-to-Convert-Binary-Matrix-to-Zero-Matrix.cpp) | _O(m * n * 2 ^ (m \* n))_ | _O(2 ^ (m \* n))_ | Hard | BFS | | | 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 | +| 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 @@ -255,9 +352,14 @@ 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 | | +| # | 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 | |
@@ -267,11 +369,12 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # BackTracking -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| --- | ------------------------------------------------------------------- | --------------------------------- | ------------------------- | ----------- | ---------- | ---------------- | ---- | -| 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 | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| --- | ------------------------------------------------------------------- | --------------------------------- | ------------------------- | ----------- | ---------- | ------------------- | ---- | +| 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 | |
@@ -281,16 +384,20 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Dynamic Programming -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | --------------------------------------------------------------------------------------------- | ---------------------------------------------- | --------- | -------- | ---------- | -------------------- | ---- | -| 416 | [ Partition Equal Subset Sum](https://leetcode.com/problems/partition-equal-subset-sum/) | [C++](./C++/Partition-Equal-Subset-Sum.cpp) | _O(n^2)_ | _O(n^2)_ | Medium | DP | | -| 056 | [Wildcard Matching](https://leetcode.com/problems/wildcard-matching/) | [Python](./Python/wildcard-matching.py) | _O(n^2)_ | _O(n^2)_ | Hard | | -| 343 | [Integer Break](https://leetcode.com/problems/integer-break/) | [C++](./C++/Integer-Break.cpp) | _O(n^2)_ | _O(n)_ | Medium | | -| 139 | [Word Break](https://leetcode.com/problems/word-break/) | [Python](./Python/word-break-1.py) | _O(n^3)_ | _O(n)_ | Medium | DP | | -| 1092 | [Shortest Common Supersequence](https://leetcode.com/problems/shortest-common-supersequence/) | [C++](./C++/Shortest-Common-Supersequence.cpp) | _O(n^2)_ | _O(n^2)_ | Hard | DP | | -| 72 | [Edit Distance](https://leetcode.com/problems/edit-distance/) | [Python](./Python/edit-distance.py) | _O(N\*M)_ | _O(n^2)_ | Medium | Levenshtein Distance | | -| 91 | [Decode ways](https://leetcode.com/problems/decode-ways/) | [Python](./Python/decode-ways.py) | _O(N)_ | _O(N)_ | Easy | DP | | -| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game/) | [Python](./Python/divisor-game.py) | _O(N^2)_ | _O(N)_ | Easy | DP | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| ---- | ------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | --------- | --------- | ---------- | -------------------- | ---- | +| 416 | [ Partition Equal Subset Sum](https://leetcode.com/problems/partition-equal-subset-sum/) | [C++](./C++/Partition-Equal-Subset-Sum.cpp) | _O(n^2)_ | _O(n^2)_ | Medium | DP | | +| 056 | [Wildcard Matching](https://leetcode.com/problems/wildcard-matching/) | [Python](./Python/wildcard-matching.py) | _O(n^2)_ | _O(n^2)_ | Hard | | +| 343 | [Integer Break](https://leetcode.com/problems/integer-break/) | [C++](./C++/Integer-Break.cpp) | _O(n^2)_ | _O(n)_ | Medium | | +| 139 | [Word Break](https://leetcode.com/problems/word-break/) | [Python](./Python/word-break-1.py) | _O(n^3)_ | _O(n)_ | Medium | DP | | +| 1092 | [Shortest Common Supersequence](https://leetcode.com/problems/shortest-common-supersequence/) | [C++](./C++/Shortest-Common-Supersequence.cpp) | _O(n^2)_ | _O(n^2)_ | Hard | DP | | +| 72 | [Edit Distance](https://leetcode.com/problems/edit-distance/) | [Python](./Python/edit-distance.py) | _O(N\*M)_ | _O(n^2)_ | Medium | Levenshtein Distance | | +| 91 | [Decode ways](https://leetcode.com/problems/decode-ways/) | [Python](./Python/decode-ways.py) | _O(N)_ | _O(N)_ | Easy | DP | | +| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game/) | [Python](./Python/divisor-game.py) | _O(N^2)_ | _O(N)_ | Easy | DP | | +| 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 | |
@@ -306,6 +413,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version/) | [Java](./Java/May-LeetCoding-Challenge/Day-1-First-Bad-Version.java)
[JavaScript](./JavaScript/First-Bad-Version.js) | _O(logn)_ | _O(1)_ | Easy | | Binary Search | | 033 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) | [Python](./Python/search-in-rotated-sorted-array.py) | _O(logn)_ | _O(1)_ | Medium | | Binary Search | | 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) | [Python](./Python/find-minimum-in-rotated-sorted-array.py) | _O(logn)_ | _O(1)_ | Medium | | Binary Search | +| 704 | [Binary Search](https://leetcode.com/problems/binary-search/) | [C++](./C++/BinarySearch.cpp) | _O(logn)_ | _O(1)_ | Easy | | Binary Search |
@@ -315,11 +423,22 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Graph -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | -------- | --------- | ---------- | ----- | -------------- | -| 1042 | [Flower Planting with No Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent/) | [Python](./Python/1042_FlowerPlantingwithNoAdjacent.py) | _O(V+E)_ | _O(2V+E)_ | Medium | Graph | Graph Coloring | +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| ---- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | --------------- | --------- | ---------- | ----- | --------------------------------- | +| 207 | [Course Schedule](https://leetcode.com/problems/course-schedule/) | [C++](./C++/Course-Schedule.cpp) | _O(V+E)_ | _O(V+E)_ | Medium | Graph | Cycle Detection in Directed Graph | +| 1042 | [Flower Planting with No Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent/) | [Python](./Python/1042_FlowerPlantingwithNoAdjacent.py) | _O(V+E)_ | _O(2V+E)_ | Medium | Graph | Graph Coloring | +| 797 | [All Paths From Source to Target](https://leetcode.com/problems/all-paths-from-source-to-target/) | [Java](./Java/All_Paths_From_Source_to_Target.java) | _O(N^2)_ | _O(N)_ | Medium | Graph | DFS | +| 934 | [Shortest Bridge](https://leetcode.com/problems/shortest-bridge/) | [C++](./C++/Shortest-Bridge.cpp) | _O(V)_ | _O(V)_ | Medium | Graph | DFS + BFS | +| 1192 | [Critical Connections in a Network](https://leetcode.com/problems/critical-connections-in-a-network/) | [C++](./C++/Critical-Connections-in-a-Network.cpp) | _O(V+E)_ | _O(4V+E)_ | Hard | Graph | Tarjan's Algorithm | +| 113 | [Path Sum II](https://leetcode.com/problems/path-sum-ii/) | [C++](./C++/Critical-Path-Sum-II.cpp) | _O(V+E)_ | _O(V)_ | Medium | Graph | DFS | +| 785 | [Is Graph Bipartite?](https://leetcode.com/problems/is-graph-bipartite/) | [C++](./C++/Is-Graph-Bipartite.cpp) | _O(V+E)_ | _O(V)_ | Medium | Graph | BFS | +| 947 | [Most Stones Removed with Same Row or Column](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/) | [C++](./C++/Most-Stones-Removed-with-Same-Row-or-Column.cpp) | _O(V)_ | _O(2V)_ | Medium | Graph | Union Find | | [C++](./C++/Most-Stones-Removed-with-Same-Row-or-Column.cpp) | _O(V)_ | _O(2V)_ | Medium | Graph | Union Find | +| 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii/) | [C++](./C++/Course-Schedule-II.cpp) | _O(V+E)_ | _O(V)_ | Medium | Graph | BFS | +| 1627 | [Graph Connectivity with Threshold](https://leetcode.com/problems/graph-connectivity-with-threshold/) | [Java](./Java/graph_connectivity_with_threshold.java) | _O(V.logV + Q)_ | _O(V)_ | Hard | Graph | Union Find + Sieve | +| 1631 | [Path with Minimum Effort](https://leetcode.com/problems/path-with-minimum-effort/) | [Java](./Java/path-with-minimum-effort.java) | _O(V^2)_ | _O(V)_ | Medium | Graph | Dijkstra's Shortest Path |
+ @@ -327,15 +446,17 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Learning Resources -1.) [Cracking the Coding Interview (Indian Edition)](https://amzn.to/3lgLYc9) +codedecks + +1.) [Cracking the Coding Interview (Indian Edition)](https://amzn.to/2H0dHy6) -2.) [Data Structures and Algorithms Made Easy in Java](https://amzn.to/3fJXsRC) +2.) [Data Structures and Algorithms Made Easy in Java](https://amzn.to/33YqWbT) -3.) [Data Structure and Algorithmic Thinking with Python](https://amzn.to/30Ldczp) +3.) [Data Structure and Algorithmic Thinking with Python](https://amzn.to/3lz22p4) -4.) [Head First Design Patterns](https://amzn.to/3jfly90) +4.) [Head First Design Patterns](https://amzn.to/37426Jk) -5.) [Dynamic Programming for Coding Interviews](https://amzn.to/31K16po) +5.) [Dynamic Programming for Coding Interviews](https://amzn.to/3jVSPqu) DISCLAIMER: This above mentioned resources have affiliate links, which means if you buy one of the product from my links, I’ll receive a small commission. This helps support the channel and allows us to continue to add more tutorial. Thank you for the support! @@ -347,33 +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/) | +| 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/) -
diff --git a/_config.yml b/_config.yml index fc24e7a6..8bbf7943 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-hacker \ No newline at end of file +theme: jekyll-theme-hacker