From c56a9f02b5494422b0c1982aae5ddfaab2d334a7 Mon Sep 17 00:00:00 2001 From: Pranay Chauhan <52269813+PranayChauhan2516@users.noreply.github.com> Date: Tue, 6 Oct 2020 17:30:27 +0530 Subject: [PATCH 001/157] Added 70. Climbing Stairs Java (#71) * Udating README.md (Added 70.Climbing Stairs) * 70. Climbing Stairs(Java) * Optimising 70. Climbing Stairs to O(1) space * Changed space complexity of 70. Climbing Stairs --- Java/climbing-stairs.java | 12 ++++++++++++ README.md | 1 + 2 files changed, 13 insertions(+) create mode 100644 Java/climbing-stairs.java diff --git a/Java/climbing-stairs.java b/Java/climbing-stairs.java new file mode 100644 index 00000000..d5173cd4 --- /dev/null +++ b/Java/climbing-stairs.java @@ -0,0 +1,12 @@ +class Solution { + public int climbStairs(int n) { + int prev1=1, prev2=2, cur=0; + if(n<=2) return n; + for(int i=3;i<=n;++i) { + cur=prev1+prev2; + prev1=prev2; + prev2=cur; + } + return cur; + } +} diff --git a/README.md b/README.md index ed18e92a..0f4164a4 100644 --- a/README.md +++ b/README.md @@ -291,6 +291,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 070 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | [Java](./Java/climbing-stairs.java) | _O(N)_ | _O(1)_ | Easy | DP | |
From 534de6c3935d6823745682a5c3dbde538e8e2286 Mon Sep 17 00:00:00 2001 From: ongzx Date: Tue, 6 Oct 2020 20:05:20 +0800 Subject: [PATCH 002/157] Add solution for leetcode #152 in javascript (#68) * Add solution for leetcode #152 in javascript * update readme Co-authored-by: Chi Hi Ong --- JavaScript/152.Maximum-Product-Subarray.js | 37 ++++++++++++++++++++++ README.md | 1 + 2 files changed, 38 insertions(+) create mode 100644 JavaScript/152.Maximum-Product-Subarray.js 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/README.md b/README.md index 0f4164a4..66065bc0 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
From 7c5ba68e20ff6537dc0ff0b21bb1c84c343bb89c Mon Sep 17 00:00:00 2001 From: Pranay Chauhan <52269813+PranayChauhan2516@users.noreply.github.com> Date: Wed, 7 Oct 2020 08:52:21 +0530 Subject: [PATCH 003/157] 73.set matrix zeroes (#72) * Added 73. Set Matrix Zeroes (Java) * Updated Readme Added 73. SetMatrixZeroes Java --- Java/set-matrix-zeroes.java | 34 ++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 35 insertions(+) create mode 100644 Java/set-matrix-zeroes.java 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/README.md b/README.md index 66065bc0..976711aa 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
From 6ae907257d4528b15bf15b1f2f27561f817cc70b Mon Sep 17 00:00:00 2001 From: Tarun Singh Date: Wed, 7 Oct 2020 08:55:15 +0530 Subject: [PATCH 004/157] Added 933. Number of Recent Calls (#70) * Added 933. Number of Recent Calls * Update README.md As stated I have updated the README.md file and listed the problem under queue section. Also I have added myself to the contributors list. --- C++/Number-of-Recent-Calls.cpp | 20 ++++++++++++++++++++ README.md | 14 ++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 C++/Number-of-Recent-Calls.cpp diff --git a/C++/Number-of-Recent-Calls.cpp b/C++/Number-of-Recent-Calls.cpp new file mode 100644 index 00000000..ade46ba3 --- /dev/null +++ b/C++/Number-of-Recent-Calls.cpp @@ -0,0 +1,20 @@ +#include +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/README.md b/README.md index 976711aa..358c2d0d 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,18 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu

+# 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 + +
+
+ ⬆️ Back to Top +
+
+ # Tree | # | Title | Solution | Time | Space | Difficulty | Tag | Note | @@ -375,6 +387,8 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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/) | +
From f314454f2eca0e373165a14a20433626102a3156 Mon Sep 17 00:00:00 2001 From: Ishu Raj Date: Wed, 7 Oct 2020 09:54:59 +0530 Subject: [PATCH 005/157] Dungeon Game.cpp added (#74) * teemo-attacking.cpp added * Comments added * Comments added and README.md updated * Update Best-Time-to-Buy-and-Sell-Stock-II.cpp * number-of-recent-calls.cpp added * dungeon-game.cpp added * Update README.md * Unnecessary file deleted * Create longest arithmetic subsequence longest arithemetic subsequence leetcode * Revert "Update Best-Time-to-Buy-and-Sell-Stock-II.cpp" * Unnecessary files deleted * README.md updated * README.md fixed * README.md updated Co-authored-by: Chelcy-millenika <54374275+Chelcy-millenika@users.noreply.github.com> Co-authored-by: Gidijala uday srinu <55196913+udaysrinu@users.noreply.github.com> --- C++/dungeon-game.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 5 ++-- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 C++/dungeon-game.cpp 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/README.md b/README.md index 358c2d0d..1f36d890 100644 --- a/README.md +++ b/README.md @@ -216,8 +216,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp)| _O(n)_ | _O(n)_ | Medium | |
@@ -305,8 +304,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +
⬆️ Back to Top From b1f92a845acd807de9a1260f9e5c07473fa23b20 Mon Sep 17 00:00:00 2001 From: Alan Tsui Date: Wed, 7 Oct 2020 00:57:44 -0400 Subject: [PATCH 006/157] Added solutions 12. & 13., Int to Roman & Roman to Int (#76) * Added solutions for Integer to Roman (q. 12) and Roman to Integer (q. 13) * Updated README.md * Removed main methods --- Java/integer-to-roman.java | 60 ++++++++++++++++++++++++++++++++++++++ Java/roman-to-integer.java | 54 ++++++++++++++++++++++++++++++++++ README.md | 4 ++- 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 Java/integer-to-roman.java create mode 100644 Java/roman-to-integer.java diff --git a/Java/integer-to-roman.java b/Java/integer-to-roman.java new file mode 100644 index 00000000..066721b1 --- /dev/null +++ b/Java/integer-to-roman.java @@ -0,0 +1,60 @@ +public class IntegerToRoman{ + public static String numberToRoman(int number){//Converts a number into a roman numerial + String roman = ""; + while(number != 0){//checks if the number is not equal to 0, if it is not equal then there is more processing to be done + if(number >= 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/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/README.md b/README.md index 1f36d890..195a3823 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | +| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | |
⬆️ Back to Top From 240df0e07b39fdabb11c5f1916539d25475f4e2f Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 7 Oct 2020 13:00:45 +0530 Subject: [PATCH 007/157] Update README.md --- README.md | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 195a3823..a67e3ac9 100644 --- a/README.md +++ b/README.md @@ -182,25 +182,14 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 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 | | - -| # | 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 +
From 50e7143cc4921c5defaf31a699122c39a51fc2c4 Mon Sep 17 00:00:00 2001 From: ongzx Date: Wed, 7 Oct 2020 15:34:14 +0800 Subject: [PATCH 008/157] Add leetcode #98 solution (#65) Co-authored-by: Chi Hi Ong Co-authored-by: Gourav Rusiya --- JavaScript/98.Validate-Binary-Search-Tree.js | 52 ++++++++++++++++++++ README.md | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 JavaScript/98.Validate-Binary-Search-Tree.js 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/README.md b/README.md index a67e3ac9..64108ee4 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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
From 8747cb983f14047b65919a5200261507c688fa5e Mon Sep 17 00:00:00 2001 From: ongzx Date: Wed, 7 Oct 2020 15:35:39 +0800 Subject: [PATCH 009/157] Add solution for leetcode #146 (#67) Co-authored-by: Chi Hi Ong Co-authored-by: Gourav Rusiya --- JavaScript/146.LRU-Cache.js | 91 +++++++++++++++++++++++++++++++++++++ README.md | 3 +- 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 JavaScript/146.LRU-Cache.js 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/README.md b/README.md index 64108ee4..fede5bee 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 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 | |
From c692b30cec30d9aed7b195d6079cf123376ee6f6 Mon Sep 17 00:00:00 2001 From: ongzx Date: Wed, 7 Oct 2020 15:46:07 +0800 Subject: [PATCH 010/157] Add Leetcode #5 solution (#66) Co-authored-by: Chi Hi Ong --- JavaScript/5.Longest-Palindromic-Substring.js | 54 +++++++++++++++++++ README.md | 2 + 2 files changed, 56 insertions(+) create mode 100644 JavaScript/5.Longest-Palindromic-Substring.js 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/README.md b/README.md index fede5bee..3ca417d7 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | --- | --------------------------------------------------------------------------------------------- | --------------------------------------------------- | -------- | ------ | ---------- | --- | ---------------- | | 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 | | | +| 005 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | [JavaScript](./JavaScript/5.Longest-Palindromic-Substring.js) | _O(N^2)_ | _O(1)_ | Medium | | | +
⬆️ Back to Top From d817568fd4a25dde840d6874704099770cc0e28e Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 7 Oct 2020 13:17:36 +0530 Subject: [PATCH 011/157] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ca417d7..674bff80 100644 --- a/README.md +++ b/README.md @@ -218,9 +218,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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 | +| 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 | | | -| 005 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | [JavaScript](./JavaScript/5.Longest-Palindromic-Substring.js) | _O(N^2)_ | _O(1)_ | Medium | | |
From d9cccb9072b039944b6153a4623d28eec77fb86d Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 7 Oct 2020 13:18:54 +0530 Subject: [PATCH 012/157] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 674bff80..3a74100b 100644 --- a/README.md +++ b/README.md @@ -231,8 +231,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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 | | +| 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 | | | 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 | | From 9ec84034efbb13654fa3b1fd88df04cda7f1bd7a Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 7 Oct 2020 13:20:52 +0530 Subject: [PATCH 013/157] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 3a74100b..4059e235 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,6 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | @@ -201,7 +200,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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) | +| 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)_ | | | From 6a7f26809dc644d81853619718af12fa854db614 Mon Sep 17 00:00:00 2001 From: Jaseem ck <32933879+Jaseemck@users.noreply.github.com> Date: Fri, 9 Oct 2020 10:04:02 +0530 Subject: [PATCH 014/157] Group anagram py - Updated Readme (#79) Co-authored-by: Gourav Rusiya --- Python/group_anagram.py | 28 ++++++++++++++++++++++++++++ README.md | 4 +++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Python/group_anagram.py 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/README.md b/README.md index 4059e235..f9228965 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | @@ -380,7 +382,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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/) | - +| [Jaseem ck](https://github.com/Jaseemck)
| India | Python | [Github](https://github.com/Jaseemck) |
From f7c023cfee22f461a77b1333b828f5a492d2feb6 Mon Sep 17 00:00:00 2001 From: Hardik Gupta <42604986+harrdy272@users.noreply.github.com> Date: Fri, 9 Oct 2020 10:05:15 +0530 Subject: [PATCH 015/157] merge-k-sorted-lists code addition (#78) Co-authored-by: Gourav Rusiya --- C++/merge-k-sorted-lists.cpp | 49 ++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 51 insertions(+) create mode 100644 C++/merge-k-sorted-lists.cpp 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/README.md b/README.md index f9228965..1ddd6a1a 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 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 | |
@@ -382,6 +383,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) |
From 2ececc010fc3e723e3e0e853c45dce3f2d34ac46 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 10 Oct 2020 18:59:41 +0530 Subject: [PATCH 016/157] Create number-complement.java --- Java/number-complement.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Java/number-complement.java 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; + } +} From a2bb5252aa2c9771405da6589ae8656c441774ab Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 10 Oct 2020 19:02:53 +0530 Subject: [PATCH 017/157] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1ddd6a1a..b1af3af6 100644 --- a/README.md +++ b/README.md @@ -68,11 +68,12 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Bit Manipulation -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | | ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------- | | 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 | | | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _O(1)_ | _O(1)_ | Easy | | | +| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py) | _O(n)_ | _O(1)_ | Easy | | |
From adb3d9e4609d45bdcdfd671a7420a75c9e9f9d27 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 10 Oct 2020 19:09:19 +0530 Subject: [PATCH 018/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1af3af6..59755a22 100644 --- a/README.md +++ b/README.md @@ -358,7 +358,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if ## Authors -- [Gourav Rusiya](https://github.com/GouravRusiya30/) +- | [Gourav Rusiya](https://github.com/GouravRusiya30/)

From c250c247eade1380eae7d6201271c114b4a33bf3 Mon Sep 17 00:00:00 2001 From: Atri Chaturvedi Date: Sat, 10 Oct 2020 22:07:22 +0530 Subject: [PATCH 019/157] BFS Solution added (#80) * Added the file * Added word-ladder program * Update README.md --- Java/word-ladder.java | 57 +++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 58 insertions(+) create mode 100644 Java/word-ladder.java diff --git a/Java/word-ladder.java b/Java/word-ladder.java new file mode 100644 index 00000000..ac66c80c --- /dev/null +++ b/Java/word-ladder.java @@ -0,0 +1,57 @@ +/* +Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that: + +Only one letter can be changed at a time. +Each transformed word must exist in the word list. +Note: + +Return 0 if there is no such transformation sequence. +All words have the same length. +All words contain only lowercase alphabetic characters. +You may assume no duplicates in the word list. +You may assume beginWord and endWord are non-empty and are not the same. + +Problem Link: https://leetcode.com/problems/word-ladder/ +It is a popular interview program which is based on BFS +*/ +import java.util.*; +class Solution { + public int ladderLength(String beginWord, String endWord, List 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 [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 | +| 200 | [Word Ladder](https://leetcode.com/problems/word-ladder/) | [Java](./Java/word-ladder.java) | O(N^2 \* M) | O(N \* M) | Medium | BFS |
From 5eebaaaef844170724f5dba155615c0256b292a5 Mon Sep 17 00:00:00 2001 From: Anushka Verma Date: Sat, 10 Oct 2020 22:09:42 +0530 Subject: [PATCH 020/157] add binary search solution (#83) * add binary search solution * update README.md --- C++/BinarySearch.cpp | 33 +++++ README.md | 300 +++++++++++++++++++++---------------------- 2 files changed, 183 insertions(+), 150 deletions(-) create mode 100644 C++/BinarySearch.cpp 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/README.md b/README.md index 30be559f..4d7fe17f 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,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,40 +40,40 @@ 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 | Tutorial | -| ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------- | +| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | +| ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------- | | 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 | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _O(1)_ | _O(1)_ | Easy | | | -| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py) | _O(n)_ | _O(1)_ | Easy | | | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _O(1)_ | _O(1)_ | Easy | | | +| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py) | _O(n)_ | _O(1)_ | Easy | | |
@@ -83,30 +83,29 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # 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 | | -| 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 | - +| # | 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 | | +| 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 |
@@ -132,16 +131,16 @@ 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 | | -| 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 | | +| # | 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 | | +| 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 | |
@@ -164,9 +163,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # 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 +| # | 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 |
@@ -176,21 +175,21 @@ 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)
[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 +| # | 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)
[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 |
@@ -200,16 +199,16 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Hash Table -| # | Title | Solution | Time | Space | Difficulty | Tag | Video Explanation | -| --- | ------------------------------------------------------------- | --------------------------------------------------------------- | ------ | ------ | ---------- | --- | ------------------------------------------------------- | -| 001 | [Two Sum](https://leetcode.com/problems/two-sum/) | [Java](./Java/two-sum.java)
[Python](./Python/1_TwoSum.py)
[C++](./C++/two-sum.cpp) | _O(N)_ | _O(N)_ | Easy | | [Tutorial](https://youtu.be/47xMuvwP7zQ) | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [Java](./Java/valid-anagram.java) | _O(n)_ | _O(1)_ | Easy | | [Tutorial](https://www.youtube.com/watch?v=sbX1Ze9lNQE) | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Java](./Java/LRU-Cache.java) | | | Medium | | | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | [Python](./Python/contains-duplicate.py) | _O(n)_ | _O(n)_ | | | -| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp)| _O(n)_ | _O(n)_ | Medium | | -| 049 | [Group Anagrams](https://leetcode.com/problems/group-anagrams/) |[Python](./Python/group_anagram.py)| _O(nlogn)_ | _O(1)_ | Easy | | -| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Javascript](../JavaScript/146.LRU-Cache.js) | _O(log(n))_ | _O(n)_ | Medium | | +| # | 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 | |
@@ -219,10 +218,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Two Pointer -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| --- | --------------------------------------------------------------------------------------------- | --------------------------------------------------- | -------- | ------ | ---------- | --- | ---------------- | +| # | 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 | | | +| 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 | | |
@@ -232,16 +231,17 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Math -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| --- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ----------------- | ------ | ---------- | ------ | ---- | -| 050 | [Pow(x, n)](https://leetcode.com/problems/powx-n/) | [Python](./Python/50.Powxn.py)
[JavaScript](./JavaScript/50.Powxn.js) | _O(n)_ | _O(1)_ | Medium | Math | | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [C++](./C++/Count-Primes.cpp) | _O(n(log(logn)))_ | _O(n)_ | Easy | Math | | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [C++](./C++/Excel-Sheet-Column-Title.cpp) | _O(n)_ | _O(n)_ | Easy | String | | -| 007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](./Java/reverse-integer.java)
[C++](./C++/Reverse-Integer.cpp) | _O(n)_ | _O(n)_ | Easy | Math | | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | -| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | -| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | | +| # | 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 | | +| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [C++](./C++/Excel-Sheet-Column-Title.cpp) | _O(n)_ | _O(n)_ | Easy | String | | +| 007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](./Java/reverse-integer.java)
[C++](./C++/Reverse-Integer.cpp) | _O(n)_ | _O(n)_ | Easy | Math | | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | +| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | | +
⬆️ Back to Top @@ -276,11 +276,11 @@ 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 | |
@@ -290,19 +290,18 @@ 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 | | -| 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 | | - +| # | 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 | |
@@ -318,6 +317,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 |
@@ -359,34 +359,34 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if ## Authors -- | [Gourav Rusiya](https://github.com/GouravRusiya30/)
+- | [Gourav Rusiya](https://github.com/GouravRusiya30/)

## Contributors -| Name | Country | Programming Language | Where to find you
(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...) | -| ------------------------------------------------------------------------------------------------------------------------------------------------ | ------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [Gourav R](https://github.com/GouravRusiya30/)
| India | Java | [codedecks](https://www.youtube.com/c/codedecks/)
[Hackerrank](https://www.hackerrank.com/gouravrusiya786)
[LeetCode](https://leetcode.com/rusiya/) | -| [Dima Vishnevetsky](https://github.com/dimshik100)
| Israel | JavaScript | [Twitter](https://twitter.com/dimshik100)
[Facebook](https://www.facebook.com/dimshik) | -| [Anuj Sharma](https://github.com/Optider/)
| India | Python | [Github](https://github.com/Optider) | -| [Lokendra Bohra](https://github.com/lokendra1704/)
| India | Python | [Leetcode](https://t.co/u0OByxhcHA)
[Hackerrank](https://www.hackerrank.com/lokendra17) | -| [Yuri Spiridonov](https://github.com/YuriSpiridonov)
| Russia | Python | [Twitter](https://twitter.com/YuriSpiridonov)
[Leetcode](https://leetcode.com/yurispiridonov/)
[Hackerrank](https://www.hackerrank.com/YuriSpiridonov) | -| [Naveen Kashyap](https://github.com/naveenkash)
| India | Javascript | [Twitter](https://twitter.com/naveen_kashyapp)
[Leetcode](https://leetcode.com/naveenkash/) | -| [Rudra Mishra](https://github.com/Rudra407)
| India | C++ | [Twitter](https://twitter.com/ruDra_Mishra407)
[Leetcode](https://leetcode.com/rudramishra/) | -| [Sachin Singh Negi](https://github.com/sachinnegi)
| India | Python | [Twitter](https://twitter.com/SachinSinghNe17)
[Leetcode](https://leetcode.com/negisachin688/)
[Hackerrrak](https://www.hackerrank.com/negisachin688) | -| [Girish Thatte](https://github.com/girishgr8/)
| India | Java | [Leetcode](https://leetcode.com/girish13/)
[Hackerrank](https://www.hackerrank.com/procoder_13)
[Codechef](https://www.codechef.com/procoder_13) | -| [Kevin Chittilapilly](https://github.com/KevinChittilapilly)
| India | Java | [Leetcode](https://leetcode.com/being_kevin/)
[Hackerrank](https://www.hackerrank.com/ckevinvarghese11)
[Kaggle](https://www.kaggle.com/kevinchittilapilly) | -| [Nour Grati](https://github.com/Nour-Grati)
| Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/)
[Hackerrank](https://www.hackerrank.com/noor_grati)
[Twitter](https://twitter.com/GratiNour1) -| [Avinash Trivedi](https://github.com/trivediavinash)
| India | C++ | [Leetcode](https://leetcode.com/avi_002/) | -| [Ishika Goel](https://github.com/ishikagoel5628)
| India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) | -| [Fenil Dobariya](https://github.com/ifenil)
| India | Java | [Github](https://github.com/ifenil) | -| [Prashansa Tanwar](https://github.com/prashansatanwar)
| India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) | -| [Ishu Raj](https://github.com/ir2010)
| India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) | -| [Rakesh Bhadhavath](https://github.com/Revenge-Rakesh)
| India | Java | [Leetcode](https://leetcode.com/goal_cracker/) | -| [Tarun Singh](https://github.com/TarunSingh56)
| India | C++ | [Leetcode](https://leetcode.com/_tarun/) | -| [Hardik Gupta](https://github.com/harrdy272)
| India | C++ | [codeforces](https://codeforces.com/profile/harrdy272)
[codechef](https://www.codechef.com/users/hardikg272)
[Hackerrank](https://www.hackerrank.com/hardikg272)
[LeetCode](https://leetcode.com/hardikg272/) | -| [Jaseem ck](https://github.com/Jaseemck)
| India | Python | [Github](https://github.com/Jaseemck) | +| 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) |
From 7ab026cb3f68f43701d0b4b52f426b1cf3d5680d Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 10 Oct 2020 23:00:36 +0530 Subject: [PATCH 021/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d7fe17f..9f1ae087 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------- | | 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 | | 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _O(1)_ | _O(1)_ | Easy | | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _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) | _O(n)_ | _O(1)_ | Easy | | |
From 4c1ad6b3df349c1d4c39c978a17e08c4f8216a60 Mon Sep 17 00:00:00 2001 From: Anushka Verma Date: Sun, 11 Oct 2020 10:15:44 +0530 Subject: [PATCH 022/157] add solution to course schedule problem (#84) --- C++/Course Schedule.cpp | 55 +++++++++++++++++++++++++++++++++++++++++ README.md | 21 ++++++++-------- 2 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 C++/Course Schedule.cpp diff --git a/C++/Course Schedule.cpp b/C++/Course Schedule.cpp new file mode 100644 index 00000000..6b03b1f5 --- /dev/null +++ b/C++/Course Schedule.cpp @@ -0,0 +1,55 @@ +//Problem Statement: Course Schedule + +// There are a total of numCourses courses you have to take, labeled from 0 to numCourses-1. + +// Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] + +// Given the total number of courses and a list of prerequisite pairs, is it possible for you to finish all courses? + +// Solution: +// approach used to solve the problem: detect cycle in directed graph +// if a back edge exists in the graph, it implies that there is a cycle, thus it is not possible to finish all the courses + +class Solution { +public: + + // helper function + bool dfs(vector>& 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Bit Manipulation -| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | -| ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------- | -| 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 | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _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) | _O(n)_ | _O(1)_ | Easy | | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | +| ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | +| 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 | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _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) | _O(n)_ | _O(1)_ | Easy | | |
@@ -254,7 +254,7 @@ 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 | -| 200 | [Word Ladder](https://leetcode.com/problems/word-ladder/) | [Java](./Java/word-ladder.java) | O(N^2 \* M) | O(N \* M) | Medium | BFS | +| 200 | [Word Ladder](https://leetcode.com/problems/word-ladder/) | [Java](./Java/word-ladder.java) | O(N^2 \* M) | O(N \* M) | Medium | BFS |
@@ -327,9 +327,10 @@ 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 |
From 6f81c788073a3bedc72b92fdadee9451155b260a Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sun, 11 Oct 2020 10:18:31 +0530 Subject: [PATCH 023/157] Rename Course Schedule.cpp to Course-Schedule.cpp --- C++/{Course Schedule.cpp => Course-Schedule.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename C++/{Course Schedule.cpp => Course-Schedule.cpp} (100%) diff --git a/C++/Course Schedule.cpp b/C++/Course-Schedule.cpp similarity index 100% rename from C++/Course Schedule.cpp rename to C++/Course-Schedule.cpp From 4a1be30f67f2a03067fdd7360aae5a63ffcf44c5 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sun, 11 Oct 2020 10:19:00 +0530 Subject: [PATCH 024/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3202a8a8..7d7ac47e 100644 --- a/README.md +++ b/README.md @@ -329,7 +329,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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 | +| 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 |
From 1a189457e46a6dafa4abd58650e3da576a6229b4 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sun, 11 Oct 2020 10:41:44 +0530 Subject: [PATCH 025/157] Create FUNDING.yml --- .github/FUNDING.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..de2df3bb --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: [GouravRusiya30] From 1f9c64535f6d3f9c727c272178e6a32a18e49e45 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sun, 11 Oct 2020 10:49:30 +0530 Subject: [PATCH 026/157] Update FUNDING.yml --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index de2df3bb..92f20772 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,4 @@ # These are supported funding model platforms github: [GouravRusiya30] +custom: ["https://paypal.me/codedecks"] From d2d77bcbc3814b794ca475b72274b9a90d4679e2 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sun, 11 Oct 2020 10:52:30 +0530 Subject: [PATCH 027/157] Update FUNDING.yml --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 92f20772..0b9daa6e 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,4 +1,4 @@ # These are supported funding model platforms -github: [GouravRusiya30] +github: [codedecks-in] custom: ["https://paypal.me/codedecks"] From 65a404bf9dd473e5de06ee0201bbfc29de86350a Mon Sep 17 00:00:00 2001 From: Ilias Date: Sun, 11 Oct 2020 18:51:47 +0530 Subject: [PATCH 028/157] 730. Count Different Palindromic Subsequences (#86) * Create CountDifferentPalindromicSubsequences.cpp * Update and rename CountDifferentPalindromicSubsequences.cpp to Count-Different-Palindromic-Subsequences.cpp * Update README.md --- ...unt-Different-Palindromic-Subsequences.cpp | 90 +++++++++++++++++++ README.md | 2 + 2 files changed, 92 insertions(+) create mode 100644 C++/Count-Different-Palindromic-Subsequences.cpp 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/README.md b/README.md index 7d7ac47e..6d778c17 100644 --- a/README.md +++ b/README.md @@ -302,6 +302,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
@@ -388,6 +389,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) |
From 77a82e28076136066437d7fb342d02e9f0678c45 Mon Sep 17 00:00:00 2001 From: Pulkit-100 <40335208+Pulkit-100@users.noreply.github.com> Date: Sun, 11 Oct 2020 20:50:01 +0530 Subject: [PATCH 029/157] Added Rotting Oranges (BFS) in Python (#87) * Create 994_Rotting_Oranges.py Added Leetcode #994 Rotting Oranges solution using BFS * Update README.md --- Python/994_Rotting_Oranges.py | 47 +++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 48 insertions(+) create mode 100644 Python/994_Rotting_Oranges.py 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 [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 | | 200 | [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 |
From cebe78cae455da2326cc8ee7e98e1ada6368a786 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sun, 11 Oct 2020 20:50:47 +0530 Subject: [PATCH 030/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5f8d1eb..5daff305 100644 --- a/README.md +++ b/README.md @@ -254,7 +254,7 @@ 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 | -| 200 | [Word Ladder](https://leetcode.com/problems/word-ladder/) | [Java](./Java/word-ladder.java) | O(N^2 \* M) | O(N \* M) | 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 |
From d973a9a86ab8ca8a7d4f4d836b46106338d528da Mon Sep 17 00:00:00 2001 From: Ilias Date: Mon, 12 Oct 2020 11:48:02 +0530 Subject: [PATCH 031/157] added c++ code for 845. Longest Mountain in Array (#88) --- C++/Longest-Mountain-in-Array.cpp | 62 +++++++++++++++++++++++++++++++ README.md | 4 +- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 C++/Longest-Mountain-in-Array.cpp 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] [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 |
⬆️ Back to Top From a1834f5bb11902f5d48a2a2723148282566afa74 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Mon, 12 Oct 2020 11:50:35 +0530 Subject: [PATCH 032/157] Update _config.yml --- _config.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index fc24e7a6..5ade608c 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1,23 @@ -theme: jekyll-theme-hacker \ No newline at end of file +theme: jekyll-theme-hacker + +# Configuration for welcome - https://github.com/behaviorbot/welcome + +# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome + +# Comment to be posted to on first time issues +newIssueWelcomeComment: > + Thanks for opening your first issue here! Be sure to follow the issue template! + +# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome + +# Comment to be posted to on PRs from first time contributors in your repository +newPRWelcomeComment: > + Thanks for opening this pull request! Please check out our contributing guidelines. + +# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge + +# Comment to be posted to on pull requests merged by a first time user +firstPRMergeComment: > + Congrats on merging your first pull request! We here at behaviorbot are proud of you! + +# It is recommend to include as many gifs and emojis as possible From 57f187c23d75257394756d1596fa7c38f4cf7b5b Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Mon, 12 Oct 2020 11:54:10 +0530 Subject: [PATCH 033/157] Update _config.yml --- _config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 5ade608c..6f822bdb 100644 --- a/_config.yml +++ b/_config.yml @@ -12,7 +12,7 @@ newIssueWelcomeComment: > # Comment to be posted to on PRs from first time contributors in your repository newPRWelcomeComment: > - Thanks for opening this pull request! Please check out our contributing guidelines. + Thanks for opening this pull request! Please check out our [PR process guidelines](https://github.com/codedecks-in/LeetCode-Solutions/blob/master/PULL_REQUEST_PROCESS.md) # Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge From 58fe22863d64845a13c5cbdf2539424cb03d227e Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Mon, 12 Oct 2020 11:55:14 +0530 Subject: [PATCH 034/157] Update _config.yml --- _config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 6f822bdb..eabc38b5 100644 --- a/_config.yml +++ b/_config.yml @@ -12,7 +12,7 @@ newIssueWelcomeComment: > # Comment to be posted to on PRs from first time contributors in your repository newPRWelcomeComment: > - Thanks for opening this pull request! Please check out our [PR process guidelines](https://github.com/codedecks-in/LeetCode-Solutions/blob/master/PULL_REQUEST_PROCESS.md) + Thanks for opening this pull request! Please check out our PR process guidelines -> https://github.com/codedecks-in/LeetCode-Solutions/blob/master/PULL_REQUEST_PROCESS.md # Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge From 6681a6ce0778cdfe8f79a23dac0dc9d161b2c3c0 Mon Sep 17 00:00:00 2001 From: Mohit Bhagchandani <72273848+MohitBhagchandani0601@users.noreply.github.com> Date: Mon, 12 Oct 2020 13:17:15 +0530 Subject: [PATCH 035/157] Added All Paths From Source to Target in java (#89) --- Java/All_Paths_From_Source_to_Target.java | 29 +++++++++++++++++++++++ README.md | 1 + 2 files changed, 30 insertions(+) create mode 100644 Java/All_Paths_From_Source_to_Target.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/README.md b/README.md index ec5f66e9..e84b5ff7 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | ---- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | -------- | --------- | ---------- | ----- | --------------------------------- | | 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 |
From f532543deff4e144f942a2a363ddf524eed4a5fa Mon Sep 17 00:00:00 2001 From: Anushka Verma Date: Tue, 13 Oct 2020 12:40:58 +0530 Subject: [PATCH 036/157] add cpp solution #1288 (#91) --- C++/Remove-Covered-Intervals.cpp | 29 +++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 30 insertions(+) create mode 100644 C++/Remove-Covered-Intervals.cpp diff --git a/C++/Remove-Covered-Intervals.cpp b/C++/Remove-Covered-Intervals.cpp new file mode 100644 index 00000000..28de473f --- /dev/null +++ b/C++/Remove-Covered-Intervals.cpp @@ -0,0 +1,29 @@ +//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) diff --git a/README.md b/README.md index e84b5ff7..e5956a9c 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
From b6b8ae5f2b3f1a04d6ad4cfbdc6b2a5fc21ddae7 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Tue, 13 Oct 2020 18:04:15 +0530 Subject: [PATCH 037/157] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e5956a9c..094e30ba 100644 --- a/README.md +++ b/README.md @@ -344,15 +344,15 @@ 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) +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! From b6ef758fdefc1de3bc71c716ffc600a88aa602e0 Mon Sep 17 00:00:00 2001 From: Shamoyeeta <59931860+Shamoyeeta@users.noreply.github.com> Date: Wed, 14 Oct 2020 01:07:58 -0400 Subject: [PATCH 038/157] Added C++ code for stack problem - Remove all adjacent duplicates in string (#92) * Added C++ code for stack question- Remove all adjacent duplicates in String * Updated README.md * Update README.md * Update README.md * Updated README.md --- ...move-all-adjacent-duplicates-in-string.cpp | 30 +++++++++++++++++++ README.md | 5 +++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 C++/remove-all-adjacent-duplicates-in-string.cpp diff --git a/C++/remove-all-adjacent-duplicates-in-string.cpp b/C++/remove-all-adjacent-duplicates-in-string.cpp new file mode 100644 index 00000000..c159d45c --- /dev/null +++ b/C++/remove-all-adjacent-duplicates-in-string.cpp @@ -0,0 +1,30 @@ +class Solution { +public: + string removeDuplicates(string str) { + stack s; + string answer=""; + for(int i=0;i [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | --- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------ | ------ | ---------- | ----- | ---- | | 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 | | +| 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 | | +
@@ -393,7 +395,8 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) | +|
⬆️ Back to Top From 3b708804eba4d21316f671833998dbc490295a66 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 14 Oct 2020 11:42:14 +0530 Subject: [PATCH 039/157] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 47a31420..2bef1eb5 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Learning Resources +codedecks + 1.) [Cracking the Coding Interview (Indian Edition)](https://amzn.to/2H0dHy6) 2.) [Data Structures and Algorithms Made Easy in Java](https://amzn.to/33YqWbT) From 4cdc250c016278568022377405264ca3c5ae1f23 Mon Sep 17 00:00:00 2001 From: Shamoyeeta <59931860+Shamoyeeta@users.noreply.github.com> Date: Wed, 14 Oct 2020 07:27:03 -0400 Subject: [PATCH 040/157] Added C++ code for stack problem Baseball Game (#95) --- C++/Baseball-Game.cpp | 33 +++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 C++/Baseball-Game.cpp 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/README.md b/README.md index 2bef1eb5..3892844e 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | | 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 | |
From dccfe9a6bb5628ade91a75a676651604e72b8f9c Mon Sep 17 00:00:00 2001 From: Shamoyeeta <59931860+Shamoyeeta@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:55:31 +0530 Subject: [PATCH 041/157] Added C++ program for Stack problem Log Crawler Folder (#97) * Added C++ code for stack question- Remove all adjacent duplicates in String * Updated README.md * Update README.md * Update README.md * Updated README.md * Added new C++ program for Stack question - Baseball Game * Updated README.md * Updated README.md * Update README.md * Update README.md * Updated README.md * Added new C++ program for Stack question - Baseball Game * Updated README.md * Added java program for Stack problem Design a Stack with Increment Operation * Updated README.md * Added C++ program for Stack problem Log Crawler Folder * Updated README.md * Fixed time complexity in README.md --- C++/Crawler-Log-Folder.cpp | 18 ++++++++++ ...sign-a-Stack-With-Increment-Operation.java | 35 +++++++++++++++++++ README.md | 2 ++ 3 files changed, 55 insertions(+) create mode 100644 C++/Crawler-Log-Folder.cpp create mode 100644 Java/Design-a-Stack-With-Increment-Operation.java diff --git a/C++/Crawler-Log-Folder.cpp b/C++/Crawler-Log-Folder.cpp new file mode 100644 index 00000000..dd5c70b8 --- /dev/null +++ b/C++/Crawler-Log-Folder.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + int minOperations(vector& logs) { + stack s; //stack s is initialized and stack is empty when you are on main folder + for(int i=0;itop+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/README.md b/README.md index 3892844e..4837169e 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) | _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 | |
From 3962594336f09f99a9eaa4ec0b97066919e17a4d Mon Sep 17 00:00:00 2001 From: Shamoyeeta <59931860+Shamoyeeta@users.noreply.github.com> Date: Sat, 17 Oct 2020 10:42:47 +0530 Subject: [PATCH 042/157] Added java program for Stack problem Design a Stack with Increment operation. (#96) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4837169e..b8e8945b 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +
⬆️ Back to Top From 808eb8b58d97c1267d1bee92b4b056110582af07 Mon Sep 17 00:00:00 2001 From: Mohit Bhagchandani <72273848+MohitBhagchandani0601@users.noreply.github.com> Date: Sat, 17 Oct 2020 10:43:22 +0530 Subject: [PATCH 043/157] Added 641. Design Circular Deque problem (Topic : Queue) (#93) --- Java/design-circular-deque.java | 148 ++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 149 insertions(+) create mode 100644 Java/design-circular-deque.java diff --git a/Java/design-circular-deque.java b/Java/design-circular-deque.java new file mode 100644 index 00000000..30a20feb --- /dev/null +++ b/Java/design-circular-deque.java @@ -0,0 +1,148 @@ +/* We will use an array to store our elements. +Find the comments for a step by step description of the code. */ + + +public class MyCircularDeque { + + + int size; // keeping the count of elements in your array + int front = -1; // keeping the index of front + int rear = -1; // keeping the index of rear + int capacity; // total capacity of our DS + int arr[]; // array to store the elements + + + /** Initialize your data structure here. Set the size of the deque to be k. */ + public MyCircularDeque(int k) { // initialising capacity as k + this.size = 0 ; // and initialising the array + this.capacity = k; + arr = new int[k]; + } + + /** Adds an item at the front of Deque. Return true if the operation is successful. */ + public boolean insertFront(int value) { + if( (this.size == this.capacity)) // means queue is full + return false; + + if(front == -1) { // means queue is empty + arr[0] = value; + front = 0; + rear = 0; + this.size ++; // increase the size and return true + return true; + } + + if(front == 0) { // if front is at 0, then add at last and make front as last + arr[this.capacity - 1] = value; + front = this.capacity - 1; + }else{ // else add to the left of front and make front as front - 1; + arr[front - 1] = value; + front --; + } + this.size ++; // increase the size and return true.. + return true; + } + + /** Adds an item at the rear of Deque. Return true if the operation is successful. */ + public boolean insertLast(int value) { + + if(this.size == this.capacity) // means queue is full + return false; + + if(rear == -1) { // means queue is empty + arr[0] = value; // add the first element and return true + front = 0; + rear = 0; + this.size ++; + return true; + } + + if(rear == this.capacity - 1) { // if rear is at last, means we will have to add this element at first + arr[0] = value; // position and make rear as first + rear = 0; + }else { + arr[rear + 1] = value; // if rear is not at last, add to rear + 1 and + rear ++; // increment rear + } + this.size ++; // increase the size and return true + return true; + } + + /** Deletes an item from the front of Deque. Return true if the operation is successful. */ + public boolean deleteFront() { + + if(this.size == 0) // means queue is empty, cannot delete any element. + return false; + + if(this.size == 1) { // if there is only one element, then remove it(mark it as 0) and + arr[rear] = 0; + rear = -1; // mark rear and front as -1(like it was initially)... + front = -1; + this.size --; // also decrease the size by 1(to 0) + return true; // and return true to mark this operation as successful ... + } + + if(front == this.capacity -1) { // if front is at last position, delete that position + arr[front] = 0; // and increment front by 1, so front will now be at 0 + front = 0; + this.size --; // decrease the size by 1 marking it as empty + return true; + } + arr[front] = 0; // if front is not at last, delete from the front and increment front by 1 + front ++; + this.size --; // decrease the size by 1 marking it as empty + return true; + } + + /** Deletes an item from the rear of Deque. Return true if the operation is successful. */ + public boolean deleteLast() { + + if(this.size == 0) // means queue is empty + return false; + + if(this.size == 1) { // if there is only one element, then remove it(mark it as 0) and + arr[rear] = 0; // mark rear and front as -1(like it was initially)... + rear = -1; + front = -1; + this.size --; // also decrease the size to 0 + return true; // and return true to mark this operation as successful ... + } + + if(rear == 0) { // if there are more than one element in the array, + arr[rear] = 0; // and rear is at 0, then delete the element and reduce rear by 1 + rear = this.capacity - 1; // so basically rear will fall back to last position... + this.size --; + }else { + arr[rear] = 0; // if rear is not at 0, then decrease rear by 1 + rear --; + this.size --; + } + return true; // return true to mark the operation as successful + } + + /** Get the front item from the deque. */ + public int getFront() { + if(this.size == 0) { // if array is empty, return -1 + return -1; + } + return arr[front]; // else return the element + } + + /** Get the last item from the deque. */ + public int getRear() { + if(this.size == 0) { // if array is empty, return -1 + return -1; + } + return arr[rear]; // else return the rear + } + + /** Checks whether the circular deque is empty or not. */ + public boolean isEmpty() { + return (this.size == 0); + } + + /** Checks whether the circular deque is full or not. */ + public boolean isFull() { + return (this.size == this.capacity); + } +} diff --git a/README.md b/README.md index b8e8945b..e08056e2 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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 |
From 1d831acbf951c65b5495f5ec44a6fdccab3bb6ac Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 10:44:24 +0530 Subject: [PATCH 044/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e08056e2..f2ab1656 100644 --- a/README.md +++ b/README.md @@ -402,7 +402,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) | -| +
⬆️ Back to Top From 6ad0d686198dec4d576b660fcb84130d0a80c8d3 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 11:08:18 +0530 Subject: [PATCH 045/157] Update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index f2ab1656..2ab3b368 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,17 @@ # [LeetCode-Solutions](https://www.youtube.com/c/codedecks/) +

+ + + + + + + +

+ LOC Stars Badge Forks Badge GitHub contributors From fd370c6a3d858d6938f8253bfc6eaa4e271a0e5b Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 11:11:48 +0530 Subject: [PATCH 046/157] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2ab3b368..c2492d72 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ - + + + From a553ea45f7c2d1984a30ab1ed40f4f375bb08b64 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 11:13:17 +0530 Subject: [PATCH 047/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c2492d72..fead18cb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ - + From 4fe6c571d3fc05a04c21e28969452b85cbfeae9c Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 11:21:21 +0530 Subject: [PATCH 048/157] Update _config.yml --- _config.yml | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/_config.yml b/_config.yml index eabc38b5..8bbf7943 100644 --- a/_config.yml +++ b/_config.yml @@ -1,23 +1 @@ theme: jekyll-theme-hacker - -# Configuration for welcome - https://github.com/behaviorbot/welcome - -# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome - -# Comment to be posted to on first time issues -newIssueWelcomeComment: > - Thanks for opening your first issue here! Be sure to follow the issue template! - -# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome - -# Comment to be posted to on PRs from first time contributors in your repository -newPRWelcomeComment: > - Thanks for opening this pull request! Please check out our PR process guidelines -> https://github.com/codedecks-in/LeetCode-Solutions/blob/master/PULL_REQUEST_PROCESS.md - -# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge - -# Comment to be posted to on pull requests merged by a first time user -firstPRMergeComment: > - Congrats on merging your first pull request! We here at behaviorbot are proud of you! - -# It is recommend to include as many gifs and emojis as possible From b481659e9228d83e4b65015f9c2aec7a80cfdfff Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 11:22:04 +0530 Subject: [PATCH 049/157] Create config.yml --- .github/config.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/config.yml diff --git a/.github/config.yml b/.github/config.yml new file mode 100644 index 00000000..bdb9b079 --- /dev/null +++ b/.github/config.yml @@ -0,0 +1,16 @@ +# 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! Someone will address it right away! + While you're waiting, I just wanted to make sure you've had a chance to look at our [Readme](https://github.com/ows-ali/Hacktoberfest/blob/master/README.md) and [Contributing Guidelines](https://github.com/ows-ali/Hacktoberfest/blob/master/CONTRIBUTING.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") From df864ef2f9f66ae5039a66b11981c88c3d309cb4 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 11:24:28 +0530 Subject: [PATCH 050/157] Update config.yml --- .github/config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/config.yml b/.github/config.yml index bdb9b079..3e9c071e 100644 --- a/.github/config.yml +++ b/.github/config.yml @@ -3,7 +3,9 @@ # Comment to be posted to on first time issues newIssueWelcomeComment: > Thanks for helping us improve and opening your first issue here! Someone will address it right away! - While you're waiting, I just wanted to make sure you've had a chance to look at our [Readme](https://github.com/ows-ali/Hacktoberfest/blob/master/README.md) and [Contributing Guidelines](https://github.com/ows-ali/Hacktoberfest/blob/master/CONTRIBUTING.md). + + 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: > From 8a93e0c3765d80e51488aaf737ce7c4d3e1e6b42 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 11:34:41 +0530 Subject: [PATCH 051/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fead18cb..3725b5ce 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [LeetCode-Solutions](https://www.youtube.com/c/codedecks/) +# [LeetCode-Solutions](https://www.youtube.com/playlist?list=PLlUdLC2oSxz2Y1g6V8oRCzauOvbnKl2Ee)

From e758b5b75492a0684dc7fecc3935f035b983becb Mon Sep 17 00:00:00 2001 From: James <41566813+jameszu@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:21:13 +1300 Subject: [PATCH 052/157] Added python code for 189. Rotate Array & 137. Single Number II (#98) * Create Rotate-List.py and update README * minor fix of the link * Added 137. Single Number II Co-authored-by: Gourav Rusiya --- Python/rotate-array.py | 12 ++++++++++++ Python/single-number-ii.py | 22 ++++++++++++++++++++++ README.md | 4 ++++ 3 files changed, 38 insertions(+) create mode 100644 Python/rotate-array.py create mode 100644 Python/single-number-ii.py 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 3725b5ce..69002911 100644 --- a/README.md +++ b/README.md @@ -83,10 +83,12 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | | ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | | 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 | +| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py) | _O(n)_ | _O(1)_ | Medium | | | | 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | | 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _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) | _O(n)_ | _O(1)_ | Easy | | | +

⬆️ Back to Top @@ -119,6 +121,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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
@@ -414,6 +417,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) |
From c09572e33ecc3053fcd312c13802a0f2d2b98c9a Mon Sep 17 00:00:00 2001 From: Saumia Singhal <35730054+SaumiaSinghal@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:58:15 +0530 Subject: [PATCH 053/157] solve Critical-Connections-in-a-Network and update Readme.md (#100) --- C++/Critical-Connections-in-a-Network.cpp | 77 +++++++++++++++++++++++ README.md | 1 + 2 files changed, 78 insertions(+) create mode 100644 C++/Critical-Connections-in-a-Network.cpp diff --git a/C++/Critical-Connections-in-a-Network.cpp b/C++/Critical-Connections-in-a-Network.cpp new file mode 100644 index 00000000..20170712 --- /dev/null +++ b/C++/Critical-Connections-in-a-Network.cpp @@ -0,0 +1,77 @@ +// C++ Implemntation of Tarjan's Algorithm to find bridges in an undirected graph +// Time Complexity : O(V + E) +// For explanation, check: https://www.geeksforgeeks.org/bridge-in-a-graph/ + +class Solution { +public: + int steps = 0; + + vector 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/README.md b/README.md index 69002911..cb53cd4b 100644 --- a/README.md +++ b/README.md @@ -357,6 +357,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | +| 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 |
⬆️ Back to Top From cd4f2932cdedef5ac14a5278a818efb60c1b5998 Mon Sep 17 00:00:00 2001 From: Saumia Singhal <35730054+SaumiaSinghal@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:56:07 +0530 Subject: [PATCH 054/157] solve Shortest-Bridge and update ReadMe.md (#102) --- C++/Shortest-Bridge.cpp | 93 +++++++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 94 insertions(+) create mode 100644 C++/Shortest-Bridge.cpp 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/README.md b/README.md index cb53cd4b..de4371bf 100644 --- a/README.md +++ b/README.md @@ -356,6 +356,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
From 4d1a25fe37887368daf5c2d3a3832d14f93fccaf Mon Sep 17 00:00:00 2001 From: MorviBhojwani <32567706+MorviBhojwani@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:57:10 +0530 Subject: [PATCH 055/157] Solved Is Graph Bipartite (#103) --- C++/Is-Graph-Bipartite.cpp | 39 ++++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 40 insertions(+) create mode 100644 C++/Is-Graph-Bipartite.cpp 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | +| 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 |
⬆️ Back to Top From ca025a377adb5211a4d1f79d5083fceba067f158 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 18:38:34 +0530 Subject: [PATCH 056/157] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index f4007bcf..21065b01 100644 --- a/README.md +++ b/README.md @@ -357,7 +357,6 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | 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 |
From 51d9bbbc2914ec4912c1134688f1ac71a35c7dcb Mon Sep 17 00:00:00 2001 From: MorviBhojwani <32567706+MorviBhojwani@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:40:35 +0530 Subject: [PATCH 057/157] Solved Path Sum II(LeetCode 113(https://leetcode.com/problems/path-sum-ii/) | Graph | Medium) and updated Readme.md (#104) Co-authored-by: Gourav Rusiya --- C++/Path-Sum-II.cpp | 37 +++++++++++++++++++++++++++++++++++++ README.md | 6 ++++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 C++/Path-Sum-II.cpp 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/README.md b/README.md index 21065b01..31c06d08 100644 --- a/README.md +++ b/README.md @@ -357,8 +357,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | -| 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 | +| 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 | +
⬆️ Back to Top From 28e48faa4532e4f477511d3935be3cfcb6ba652b Mon Sep 17 00:00:00 2001 From: Saumia Singhal <35730054+SaumiaSinghal@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:42:11 +0530 Subject: [PATCH 058/157] Solved Largest Rectangle in Histogram [LeetCode 84 | Stack | Hard] and update Readme.md (#105) Co-authored-by: Gourav Rusiya --- C++/Largest-Rectangle-in-Histogram.cpp | 32 ++++++++++++++++++++++++++ README.md | 6 ++--- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 C++/Largest-Rectangle-in-Histogram.cpp diff --git a/C++/Largest-Rectangle-in-Histogram.cpp b/C++/Largest-Rectangle-in-Histogram.cpp new file mode 100644 index 00000000..68428133 --- /dev/null +++ b/C++/Largest-Rectangle-in-Histogram.cpp @@ -0,0 +1,32 @@ +// C++ stack based solution +// Time Complexity: O(n) +// Space Complexity: O(n) + +class Solution { +public: + int largestRectangleArea(vector& 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/README.md b/README.md index 31c06d08..750a3d60 100644 --- a/README.md +++ b/README.md @@ -173,8 +173,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | - +| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder/) | [C++](./C++/Crawler-Log-Folder.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | | 84 | [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 |
@@ -356,10 +355,11 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | +| 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 |
From d83a48247fddb82ab0f459e1a674adbe1151886d Mon Sep 17 00:00:00 2001 From: Saumia Singhal <35730054+SaumiaSinghal@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:43:33 +0530 Subject: [PATCH 059/157] Solved Most Stones Removed with Same Row or Column [LeetCode 947 | Graph | Medium] and update Readme.md (#101) Co-authored-by: Gourav Rusiya --- ...Stones-Removed-with-Same-Row-or-Column.cpp | 72 +++++++++++++++++++ README.md | 3 +- 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 C++/Most-Stones-Removed-with-Same-Row-or-Column.cpp 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/README.md b/README.md index 750a3d60..3b8138fa 100644 --- a/README.md +++ b/README.md @@ -359,8 +359,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | - +| 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 |
⬆️ Back to Top From 9c9b69c73c4fe44c6e8fa359a264ef57c75610d2 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 18:47:42 +0530 Subject: [PATCH 060/157] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b8138fa..116668d0 100644 --- a/README.md +++ b/README.md @@ -169,11 +169,12 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Note | | --- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------ | ------ | ---------- | ----- | ---- | | 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) | _O(n)_ | _O(n)_ | Easy | Stack | | +| 084 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | [C++](./C++/Largest-Rectangle-in-Histogram.cpp) | _O(n)_ | _O(n)_ | Hard | Stack | | 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) | _O(n)_ | _O(1)_ | Medium | Stack | | | 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 | | 84 | [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 | +| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder/) | [C++](./C++/Crawler-Log-Folder.cpp) | _O(n)_ | _O(n)_ | Easy | Stack |
From e87abfe6735c7b06ac7d94ecf6ac311914586b8c Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 18:55:22 +0530 Subject: [PATCH 061/157] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 116668d0..d6479754 100644 --- a/README.md +++ b/README.md @@ -82,12 +82,12 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | | ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | -| 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 | +| 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java)
[Python](./Python/single-number.py)
[C++](./C++/Single-Number.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR | | 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py) | _O(n)_ | _O(1)_ | Medium | | | | 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | | 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _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) | _O(n)_ | _O(1)_ | Easy | | | - +| 1486 | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) | [Java](./Java/xor-op-in-array.java) | _O(n)_ | _O(1)_ | Easy | | Using XOR |
From 8be85f27c9081345f189f0e6a2fe519f210fdcbb Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 18:56:23 +0530 Subject: [PATCH 062/157] Create xor-op-in-array.java --- Java/xor-op-in-array.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Java/xor-op-in-array.java diff --git a/Java/xor-op-in-array.java b/Java/xor-op-in-array.java new file mode 100644 index 00000000..98bab3cb --- /dev/null +++ b/Java/xor-op-in-array.java @@ -0,0 +1,11 @@ +class Solution { + public int xorOperation(int n, int start) { + int xor = start; + + for(int i=1; i Date: Sat, 17 Oct 2020 18:59:22 +0530 Subject: [PATCH 063/157] Create max-nesting-depth-parentheses.java --- Java/max-nesting-depth-parentheses.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Java/max-nesting-depth-parentheses.java 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; + } +} From 221e62ccce2f450bd0157925553e2c78e55b1ad6 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 17 Oct 2020 19:02:42 +0530 Subject: [PATCH 064/157] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d6479754..cccafbfd 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | | +| 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 | | |
From 141ca43183c37de99f7c705e9342bdf224972418 Mon Sep 17 00:00:00 2001 From: MorviBhojwani <32567706+MorviBhojwani@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:21:54 +0530 Subject: [PATCH 065/157] Solved Course Schedule II (LeetCode 210 | Graph | Medium) and updated Readme.md (#106) --- C++/Course-Schedule-II.cpp | 47 ++++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 48 insertions(+) create mode 100644 C++/Course-Schedule-II.cpp 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
⬆️ Back to Top From a63d6fd89605a29478684c482248b161b80cab90 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sun, 18 Oct 2020 18:25:27 +0530 Subject: [PATCH 066/157] Update config.yml --- .github/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/config.yml b/.github/config.yml index 3e9c071e..bb12472e 100644 --- a/.github/config.yml +++ b/.github/config.yml @@ -2,7 +2,7 @@ # Comment to be posted to on first time issues newIssueWelcomeComment: > - Thanks for helping us improve and opening your first issue here! Someone will address it right away! + # 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). From 8b4f5ae5932b1592f16b6958fb205f5981b3dda9 Mon Sep 17 00:00:00 2001 From: Vivek Das <56256802+heyyviv@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:37:52 +0530 Subject: [PATCH 067/157] Generate PR for codedecks by solving any STACK/QUEUE section problem of LeetCode #90 (#107) --- Python/621-Task-Scheduler.py | 32 ++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 33 insertions(+) create mode 100644 Python/621-Task-Scheduler.py 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/README.md b/README.md index 7934185f..e1d4a5ff 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | --- | ------------------------------------------------------------------------------- | --------------------------------------- | ------ | ------ | ---------- | --------------------- | ---- | | 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
From c20f8cb4949ff48216991fa9e21f4d7a0858b078 Mon Sep 17 00:00:00 2001 From: saranshkotnala <66181092+saranshkotnala@users.noreply.github.com> Date: Mon, 19 Oct 2020 00:09:59 +0530 Subject: [PATCH 068/157] Create 496_nextgreaterelement.py (#108) * Create 496_nextgreaterelement.py * Update README.md --- Python/496_nextgreaterelement.py | 10 ++++++++++ README.md | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 Python/496_nextgreaterelement.py 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/README.md b/README.md index e1d4a5ff..1bf982d7 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 +
From 64703f201163c52eec122c37396990df94c67953 Mon Sep 17 00:00:00 2001 From: Vivek Das <56256802+heyyviv@users.noreply.github.com> Date: Mon, 19 Oct 2020 00:10:36 +0530 Subject: [PATCH 069/157] Generate PR for codedecks by solving any STACK/QUEUE section problem of LeetCode #90 (#109) * Generate PR for codedecks by solving any STACK/QUEUE section problem of LeetCode #90 * Update README.md --- Python/622-Design-Circular-Queue.py | 80 +++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 81 insertions(+) create mode 100644 Python/622-Design-Circular-Queue.py 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/README.md b/README.md index 1bf982d7..c68c03c5 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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
From c4eae6d76ffff03a90d24594b2a57ca09a495595 Mon Sep 17 00:00:00 2001 From: Sachin Singh Negi Date: Wed, 21 Oct 2020 16:09:52 +0530 Subject: [PATCH 070/157] adding solution for indorder traversal python (#112) --- Python/Iterative-Inorder-tree-traversal.py | 23 ++++++++++++++++++++++ README.md | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Python/Iterative-Inorder-tree-traversal.py diff --git a/Python/Iterative-Inorder-tree-traversal.py b/Python/Iterative-Inorder-tree-traversal.py new file mode 100644 index 00000000..3ab91807 --- /dev/null +++ b/Python/Iterative-Inorder-tree-traversal.py @@ -0,0 +1,23 @@ +# 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 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/README.md b/README.md index c68c03c5..5a6b09a0 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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 | | +| 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) | _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 | | From da1dd59f4d7050f3a679e73ebc4d737d594784ba Mon Sep 17 00:00:00 2001 From: Sachin Singh Negi Date: Wed, 21 Oct 2020 16:36:13 +0530 Subject: [PATCH 071/157] adding solution for lruCache in python (#113) --- Python/LRUCache.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 +-- 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 Python/LRUCache.py 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/README.md b/README.md index 5a6b09a0..3c748a9f 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 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 | | | 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 | | | 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 | | @@ -204,7 +204,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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 | | +| 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) | _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 | | From 1c07823287d3c94f1098f77fb66e7159ae0fe582 Mon Sep 17 00:00:00 2001 From: MercerFrey Date: Sat, 24 Oct 2020 07:57:17 +0300 Subject: [PATCH 072/157] Binary Tree Inorder Traversal https://leetcode.com/problems/binary-tree-inorder-traversal/ (#116) * Binary Tree Inorder Traversal with recursion * Update README.md --- Python/binary-tree-inorder-traversal.py | 12 ++++++++++++ README.md | 2 ++ 2 files changed, 14 insertions(+) create mode 100644 Python/binary-tree-inorder-traversal.py diff --git a/Python/binary-tree-inorder-traversal.py b/Python/binary-tree-inorder-traversal.py new file mode 100644 index 00000000..5c2a2380 --- /dev/null +++ b/Python/binary-tree-inorder-traversal.py @@ -0,0 +1,12 @@ +# 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/README.md b/README.md index 3c748a9f..eb3e6958 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
@@ -428,6 +429,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) | +| [Meli Haktas](https://github.com/MercerFrey)
| Turkey | python | [Github](https://github.com/MercerFrey) |
From 50a97b97977a55fefcb244116f2f8383cc7e5cfc Mon Sep 17 00:00:00 2001 From: MercerFrey Date: Sat, 24 Oct 2020 11:06:39 +0300 Subject: [PATCH 073/157] Added the solution of Maximum Depth of Binary Tree (#119) * Binary Tree Inorder Traversal with recursion * Update README.md * Binary Tree Inorder Traversal with recursion * Update README.md added maximum depth * Update README.md --- Python/binary-tree-inorder-traversal.py | 5 +++++ Python/maximum-depth-of-binary-tree.py | 17 +++++++++++++++++ README.md | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Python/maximum-depth-of-binary-tree.py diff --git a/Python/binary-tree-inorder-traversal.py b/Python/binary-tree-inorder-traversal.py index 5c2a2380..d850aea7 100644 --- a/Python/binary-tree-inorder-traversal.py +++ b/Python/binary-tree-inorder-traversal.py @@ -1,3 +1,8 @@ +#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): 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/README.md b/README.md index eb3e6958..a628d1bc 100644 --- a/README.md +++ b/README.md @@ -295,7 +295,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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 | | +| 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 | |
From 9b9ebe0ac6084953fb3720c39d9a26b23c58def7 Mon Sep 17 00:00:00 2001 From: Hamza <56516922+9Hamza@users.noreply.github.com> Date: Sun, 25 Oct 2020 06:53:19 -0500 Subject: [PATCH 074/157] Added shuffle-the-array.java & Modified README.md (#118) * Added shuffle-the-array Problem * Updated README.md * Updated README.md * Modified shuffle-the-array.java * Added generate-a-string-with-characters-that-have-odd-counts.java problem Co-authored-by: Gourav Rusiya --- ...-with-characters-that-have-odd-counts.java | 21 +++++++++++++++++++ Java/shuffle-the-array.java | 18 ++++++++++++++++ README.md | 3 +++ 3 files changed, 42 insertions(+) create mode 100644 Java/generate-a-string-with-characters-that-have-odd-counts.java create mode 100644 Java/shuffle-the-array.java 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/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/README.md b/README.md index a628d1bc..a5c86dd0 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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
@@ -141,6 +142,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | | | 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Java](./Java/max-nesting-depth-parentheses.java) | _O(n)_ | _O(1)_ | Easy | | | +| 1374 | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | [Java](./Java/generate-a-string-with-characters-that-have-odd-counts.java) | _O(n)_ | _O(1)_ | Easy | | |
@@ -430,6 +432,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) |
From 95c836c856ce3c40460cd7afb1f08f9c740c090f Mon Sep 17 00:00:00 2001 From: Saurav Prateek Date: Sun, 25 Oct 2020 22:12:20 +0530 Subject: [PATCH 075/157] Adding the solution of Graph Connectivity With Threshold (#120) * Added a new Leetcode Problem 1627 * Resolving bug in readme --- Java/graph_connectivity_with_threshold.java | 66 +++++++++++++++++++++ README.md | 3 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Java/graph_connectivity_with_threshold.java 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
⬆️ Back to Top @@ -434,7 +435,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) |
⬆️ Back to Top From 1a4de52e1f9c8d415ac2927fb227f4c5f556fd59 Mon Sep 17 00:00:00 2001 From: Anushka Verma Date: Mon, 26 Oct 2020 13:34:26 +0530 Subject: [PATCH 076/157] add solution to excel sheet column number (#121) --- C++/Excel-Sheet-Column-Number.cpp | 36 +++++ README.md | 227 +++++++++++++++--------------- 2 files changed, 151 insertions(+), 112 deletions(-) create mode 100644 C++/Excel-Sheet-Column-Number.cpp diff --git a/C++/Excel-Sheet-Column-Number.cpp b/C++/Excel-Sheet-Column-Number.cpp new file mode 100644 index 00000000..b67afbee --- /dev/null +++ b/C++/Excel-Sheet-Column-Number.cpp @@ -0,0 +1,36 @@ + +//Problem Statement: Excel Sheet Column Number + +// Given a column title as appear in an Excel sheet, return its corresponding column number. + +// For example: + +// A -> 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/README.md b/README.md index 12ec0cdc..3db90713 100644 --- a/README.md +++ b/README.md @@ -80,14 +80,14 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Bit Manipulation -| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | -| ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | -| 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java)
[Python](./Python/single-number.py)
[C++](./C++/Single-Number.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR | -| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py) | _O(n)_ | _O(1)_ | Medium | | | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _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) | _O(n)_ | _O(1)_ | Easy | | | -| 1486 | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) | [Java](./Java/xor-op-in-array.java) | _O(n)_ | _O(1)_ | Easy | | Using XOR | +| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | +| ---- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | +| 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java)
[Python](./Python/single-number.py)
[C++](./C++/Single-Number.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR | +| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py) | _O(n)_ | _O(1)_ | Medium | | | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _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) | _O(n)_ | _O(1)_ | Easy | | | +| 1486 | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) | [Java](./Java/xor-op-in-array.java) | _O(n)_ | _O(1)_ | Easy | | Using XOR |
@@ -120,11 +120,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 - +| 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 |
@@ -134,14 +133,14 @@ 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 | | | -| 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 | | | +| # | 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 | | | +| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Java](./Java/max-nesting-depth-parentheses.java) | _O(n)_ | _O(1)_ | Easy | | | | 1374 | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | [Java](./Java/generate-a-string-with-characters-that-have-odd-counts.java) | _O(n)_ | _O(1)_ | Easy | | |
@@ -159,7 +158,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 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 | | | 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 | | | 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 | | @@ -171,16 +170,16 @@ 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 | | -| 084 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | [C++](./C++/Largest-Rectangle-in-Histogram.cpp) | _O(n)_ | _O(n)_ | Hard | Stack | -| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) | _O(n)_ | _O(1)_ | Medium | Stack | | -| 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 | +| # | 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 | | +| 084 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | [C++](./C++/Largest-Rectangle-in-Histogram.cpp) | _O(n)_ | _O(n)_ | Hard | Stack | +| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) | _O(n)_ | _O(1)_ | Medium | Stack | | +| 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 |
@@ -190,12 +189,12 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # 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 +| # | 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 |
@@ -207,7 +206,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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 | | +| 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) | _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 | | @@ -248,11 +247,12 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # 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 | +| # | 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 | +
⬆️ Back to Top @@ -261,16 +261,17 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Math -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| --- | ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ----------------- | ------ | ---------- | ------ | ---- | -| 050 | [Pow(x, n)](https://leetcode.com/problems/powx-n/) | [Python](./Python/50.Powxn.py)
[JavaScript](./JavaScript/50.Powxn.js) | _O(n)_ | _O(1)_ | Medium | Math | | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [C++](./C++/Count-Primes.cpp) | _O(n(log(logn)))_ | _O(n)_ | Easy | Math | | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [C++](./C++/Excel-Sheet-Column-Title.cpp) | _O(n)_ | _O(n)_ | Easy | String | | -| 007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](./Java/reverse-integer.java)
[C++](./C++/Reverse-Integer.cpp) | _O(n)_ | _O(n)_ | Easy | Math | | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | -| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | -| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| --- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ----------------- | ------ | ---------- | ------ | ---- | +| 050 | [Pow(x, n)](https://leetcode.com/problems/powx-n/) | [Python](./Python/50.Powxn.py)
[JavaScript](./JavaScript/50.Powxn.js) | _O(n)_ | _O(1)_ | Medium | Math | | +| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [C++](./C++/Count-Primes.cpp) | _O(n(log(logn)))_ | _O(n)_ | Easy | Math | | +| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/) | [C++](./C++/Excel-Sheet-Column-Number.cpp) | _O(n)_ | _O(1)_ | Easy | String | | +| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [C++](./C++/Excel-Sheet-Column-Title.cpp) | _O(n)_ | _O(n)_ | Easy | String | | +| 007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](./Java/reverse-integer.java)
[C++](./C++/Reverse-Integer.cpp) | _O(n)_ | _O(n)_ | Easy | Math | | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | +| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | |
@@ -285,7 +286,7 @@ 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 | +| 994 | [Rotten Oranges](https://leetcode.com/problems/rotting-oranges/) | [Python](./Python/994_Rotting_Oranges.py) | O(N \* M) | O(N \* M) | Medium | BFS |
@@ -295,10 +296,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Depth-First Search -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | ------------------------------------------------------------------- | --------------------------------- | ----------- | ----------- | ---------- | --- | ---- | -| 1463 | [Cherry Pickup II](https://leetcode.com/problems/cherry-pickup-ii/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n \* m)_ | _O(n \* m)_ | Hard | DFS | | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [python](./Python/maximum-depth-of-binary-tree.py) | _O(n)_ | _O(n)_ | Easy | DFS | | +| # | 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 | |
@@ -322,19 +323,19 @@ 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 | | -| 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 | | +| # | 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 | |
@@ -360,18 +361,19 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Graph -| # | 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 | +| # | 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 | +
⬆️ Back to Top @@ -408,34 +410,35 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if ## Contributors -| Name | Country | Programming Language | Where to find you
(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...) | -| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [Gourav R](https://github.com/GouravRusiya30/)
| India | Java | [codedecks](https://www.youtube.com/c/codedecks/)
[Hackerrank](https://www.hackerrank.com/gouravrusiya786)
[LeetCode](https://leetcode.com/rusiya/) | -| [Dima Vishnevetsky](https://github.com/dimshik100)
| Israel | JavaScript | [Twitter](https://twitter.com/dimshik100)
[Facebook](https://www.facebook.com/dimshik) | -| [Anuj Sharma](https://github.com/Optider/)
| India | Python | [Github](https://github.com/Optider) | -| [Lokendra Bohra](https://github.com/lokendra1704/)
| India | Python | [Leetcode](https://t.co/u0OByxhcHA)
[Hackerrank](https://www.hackerrank.com/lokendra17) | -| [Yuri Spiridonov](https://github.com/YuriSpiridonov)
| Russia | Python | [Twitter](https://twitter.com/YuriSpiridonov)
[Leetcode](https://leetcode.com/yurispiridonov/)
[Hackerrank](https://www.hackerrank.com/YuriSpiridonov) | -| [Naveen Kashyap](https://github.com/naveenkash)
| India | Javascript | [Twitter](https://twitter.com/naveen_kashyapp)
[Leetcode](https://leetcode.com/naveenkash/) | -| [Rudra Mishra](https://github.com/Rudra407)
| India | C++ | [Twitter](https://twitter.com/ruDra_Mishra407)
[Leetcode](https://leetcode.com/rudramishra/) | -| [Sachin Singh Negi](https://github.com/sachinnegi)
| India | Python | [Twitter](https://twitter.com/SachinSinghNe17)
[Leetcode](https://leetcode.com/negisachin688/)
[Hackerrrak](https://www.hackerrank.com/negisachin688) | -| [Girish Thatte](https://github.com/girishgr8/)
| India | Java | [Leetcode](https://leetcode.com/girish13/)
[Hackerrank](https://www.hackerrank.com/procoder_13)
[Codechef](https://www.codechef.com/procoder_13) | -| [Kevin Chittilapilly](https://github.com/KevinChittilapilly)
| India | Java | [Leetcode](https://leetcode.com/being_kevin/)
[Hackerrank](https://www.hackerrank.com/ckevinvarghese11)
[Kaggle](https://www.kaggle.com/kevinchittilapilly) | -| [Nour Grati](https://github.com/Nour-Grati)
| Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/)
[Hackerrank](https://www.hackerrank.com/noor_grati)
[Twitter](https://twitter.com/GratiNour1) | -| [Avinash Trivedi](https://github.com/trivediavinash)
| India | C++ | [Leetcode](https://leetcode.com/avi_002/) | -| [Ishika Goel](https://github.com/ishikagoel5628)
| India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) | -| [Fenil Dobariya](https://github.com/ifenil)
| India | Java | [Github](https://github.com/ifenil) | -| [Prashansa Tanwar](https://github.com/prashansatanwar)
| India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) | -| [Ishu Raj](https://github.com/ir2010)
| India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) | -| [Rakesh Bhadhavath](https://github.com/Revenge-Rakesh)
| India | Java | [Leetcode](https://leetcode.com/goal_cracker/) | -| [Tarun Singh](https://github.com/TarunSingh56)
| India | C++ | [Leetcode](https://leetcode.com/_tarun/) | -| [Hardik Gupta](https://github.com/harrdy272)
| India | C++ | [codeforces](https://codeforces.com/profile/harrdy272)
[codechef](https://www.codechef.com/users/hardikg272)
[Hackerrank](https://www.hackerrank.com/hardikg272)
[LeetCode](https://leetcode.com/hardikg272/) | -| [Jaseem ck](https://github.com/Jaseemck)
| India | Python | [Github](https://github.com/Jaseemck) | -| [Ilias Khan](https://github.com/IliasKhan)
| India | C++ | [codechef](https://www.codechef.com/users/iliaskhan)
[Hackerrank](ckerrank.com/iliaskhan57)
[LeetCode](https://leetcode.com/ilias_khan/)
[codeforces](http://codeforces.com/profile/iliaskhan) | -| [Shamoyeeta Saha](https://github.com/Shamoyeeta)
| India | C++ | [Hackerrank](https://www.hackerrank.com/sahashamoyeeta)
[Github](https://github.com/Shamoyeeta) | -| [James Y](https://github.com/jameszu)
| New Zealand | python | [Github](https://github.com/jameszu) | -| [Hamza B](https://github.com/9Hamza)
| Saudi Arabia | Java | [Github](https://github.com/9Hamza) | -| [Meli Haktas](https://github.com/MercerFrey)
| Turkey | python | [Github](https://github.com/MercerFrey) | -| [Saurav Prateek](https://github.com/SauravP97)
| India | Java | [Github](https://github.com/SauravP97) | +| 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) | +
⬆️ Back to Top From 90e854cdd496ea6cbc8ad25ad88d6a3969861aa0 Mon Sep 17 00:00:00 2001 From: Saurav Prateek Date: Mon, 26 Oct 2020 17:03:25 +0530 Subject: [PATCH 077/157] Adding the solution of Path with Minimum Effort (#123) --- Java/path-with-minimum-effort.java | 90 ++++++++++++++++++++++++++++++ README.md | 4 +- 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Java/path-with-minimum-effort.java 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/README.md b/README.md index 3db90713..bf4abc1c 100644 --- a/README.md +++ b/README.md @@ -373,7 +373,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
⬆️ Back to Top @@ -437,7 +437,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) | +| [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) | |
From 89909811bfc473af0c7e758daeecd80452424bed Mon Sep 17 00:00:00 2001 From: Anushka Verma Date: Mon, 26 Oct 2020 19:39:44 +0530 Subject: [PATCH 078/157] add solution to move zeroes leetcode problem (#126) * add solution to move zeroes lc problem * update readme (add profile links to contributors list) --- C++/Move-Zeroes.cpp | 23 +++++++++++++++++ README.md | 62 ++++++++++++++++++++++++--------------------- 2 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 C++/Move-Zeroes.cpp 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 189 | [Rotate-Array](https://leetcode.com/problems/rotate-array/) | [Python](./Python/rotate-array.py) | O(N) | O(1) | Medium | Array | | 496 | [next-greater-element-i](https://leetcode.com/problems/next-greater-element-i) | [Python](./Python/496_nextgreaterelement.py) | O(N) | O(1) | Medium | Array | | 1470 | [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array) | [Java](./Java/shuffle-the-array.java) | O(N) | O(1) | Easy | Array | +| 283 | [Move-Zeroes](https://leetcode.com/problems/move-zeroes/) | [C++](./C++/Move-Zeroes.cpp) | O(N) | O(1) | Easy | Array |
@@ -373,8 +374,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | +| 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 | +
+ @@ -410,34 +413,35 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if ## Contributors -| Name | Country | Programming Language | Where to find you
(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...) | -| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [Gourav R](https://github.com/GouravRusiya30/)
| India | Java | [codedecks](https://www.youtube.com/c/codedecks/)
[Hackerrank](https://www.hackerrank.com/gouravrusiya786)
[LeetCode](https://leetcode.com/rusiya/) | -| [Dima Vishnevetsky](https://github.com/dimshik100)
| Israel | JavaScript | [Twitter](https://twitter.com/dimshik100)
[Facebook](https://www.facebook.com/dimshik) | -| [Anuj Sharma](https://github.com/Optider/)
| India | Python | [Github](https://github.com/Optider) | -| [Lokendra Bohra](https://github.com/lokendra1704/)
| India | Python | [Leetcode](https://t.co/u0OByxhcHA)
[Hackerrank](https://www.hackerrank.com/lokendra17) | -| [Yuri Spiridonov](https://github.com/YuriSpiridonov)
| Russia | Python | [Twitter](https://twitter.com/YuriSpiridonov)
[Leetcode](https://leetcode.com/yurispiridonov/)
[Hackerrank](https://www.hackerrank.com/YuriSpiridonov) | -| [Naveen Kashyap](https://github.com/naveenkash)
| India | Javascript | [Twitter](https://twitter.com/naveen_kashyapp)
[Leetcode](https://leetcode.com/naveenkash/) | -| [Rudra Mishra](https://github.com/Rudra407)
| India | C++ | [Twitter](https://twitter.com/ruDra_Mishra407)
[Leetcode](https://leetcode.com/rudramishra/) | -| [Sachin Singh Negi](https://github.com/sachinnegi)
| India | Python | [Twitter](https://twitter.com/SachinSinghNe17)
[Leetcode](https://leetcode.com/negisachin688/)
[Hackerrrak](https://www.hackerrank.com/negisachin688) | -| [Girish Thatte](https://github.com/girishgr8/)
| India | Java | [Leetcode](https://leetcode.com/girish13/)
[Hackerrank](https://www.hackerrank.com/procoder_13)
[Codechef](https://www.codechef.com/procoder_13) | -| [Kevin Chittilapilly](https://github.com/KevinChittilapilly)
| India | Java | [Leetcode](https://leetcode.com/being_kevin/)
[Hackerrank](https://www.hackerrank.com/ckevinvarghese11)
[Kaggle](https://www.kaggle.com/kevinchittilapilly) | -| [Nour Grati](https://github.com/Nour-Grati)
| Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/)
[Hackerrank](https://www.hackerrank.com/noor_grati)
[Twitter](https://twitter.com/GratiNour1) | -| [Avinash Trivedi](https://github.com/trivediavinash)
| India | C++ | [Leetcode](https://leetcode.com/avi_002/) | -| [Ishika Goel](https://github.com/ishikagoel5628)
| India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) | -| [Fenil Dobariya](https://github.com/ifenil)
| India | Java | [Github](https://github.com/ifenil) | -| [Prashansa Tanwar](https://github.com/prashansatanwar)
| India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) | -| [Ishu Raj](https://github.com/ir2010)
| India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) | -| [Rakesh Bhadhavath](https://github.com/Revenge-Rakesh)
| India | Java | [Leetcode](https://leetcode.com/goal_cracker/) | -| [Tarun Singh](https://github.com/TarunSingh56)
| India | C++ | [Leetcode](https://leetcode.com/_tarun/) | -| [Hardik Gupta](https://github.com/harrdy272)
| India | C++ | [codeforces](https://codeforces.com/profile/harrdy272)
[codechef](https://www.codechef.com/users/hardikg272)
[Hackerrank](https://www.hackerrank.com/hardikg272)
[LeetCode](https://leetcode.com/hardikg272/) | -| [Jaseem ck](https://github.com/Jaseemck)
| India | Python | [Github](https://github.com/Jaseemck) | -| [Ilias Khan](https://github.com/IliasKhan)
| India | C++ | [codechef](https://www.codechef.com/users/iliaskhan)
[Hackerrank](ckerrank.com/iliaskhan57)
[LeetCode](https://leetcode.com/ilias_khan/)
[codeforces](http://codeforces.com/profile/iliaskhan) | -| [Shamoyeeta Saha](https://github.com/Shamoyeeta)
| India | C++ | [Hackerrank](https://www.hackerrank.com/sahashamoyeeta)
[Github](https://github.com/Shamoyeeta) | -| [James Y](https://github.com/jameszu)
| New Zealand | python | [Github](https://github.com/jameszu) | -| [Hamza B](https://github.com/9Hamza)
| Saudi Arabia | Java | [Github](https://github.com/9Hamza) | -| [Meli Haktas](https://github.com/MercerFrey)
| Turkey | python | [Github](https://github.com/MercerFrey) | -| [Saurav Prateek](https://github.com/SauravP97)
| India | Java | [Github](https://github.com/SauravP97)
[Codechef](https://www.codechef.com/users/srvptk)
[Codeforces](https://codeforces.com/profile/srvptk97)
[Leetcode](https://leetcode.com/srvptk97) | | +| 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/) |
From f30d14a13ae142e8a4de85096e236bcdf7e0e85e Mon Sep 17 00:00:00 2001 From: Saurav Prateek Date: Tue, 27 Oct 2020 21:49:03 +0530 Subject: [PATCH 079/157] Added leetcode solution for Buddy Strings (#128) --- Java/buddy-strings.java | 50 +++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Java/buddy-strings.java 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 1221 | [Split a String in Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings/) | [Python](./Python/split-a-string-in-balanced-strings.py) | _O(n)_ | _O(1)_ | Easy | | | | 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Java](./Java/max-nesting-depth-parentheses.java) | _O(n)_ | _O(1)_ | Easy | | | | 1374 | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | [Java](./Java/generate-a-string-with-characters-that-have-odd-counts.java) | _O(n)_ | _O(1)_ | Easy | | | - +| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | |
⬆️ Back to Top From 8f375e41c918a74247a9fbf026b67771b506bf41 Mon Sep 17 00:00:00 2001 From: HoangJames Date: Tue, 27 Oct 2020 16:20:21 +0000 Subject: [PATCH 080/157] Remove Element Pull Request (#127) * added solution to remove-element problem * Updated Readme file with Remove-Element problem Updated Readme with Remove-Element problem & user credentials --- C++/remove-element.cpp | 23 +++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 C++/remove-element.cpp diff --git a/C++/remove-element.cpp b/C++/remove-element.cpp new file mode 100644 index 00000000..1020b7e9 --- /dev/null +++ b/C++/remove-element.cpp @@ -0,0 +1,23 @@ +//O(n) time complexity and O(1) space complexity +//traverse array with fast pointer until the end +//if the value at fast pointer isn't equal to value, then swap it with whatever is at slow pointer. Increment slow after the swap. +//the value of slow will give the final length of the array as requested + +class Solution { +public: + int removeElement(vector& 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/README.md b/README.md index 9d30beed..7228bc36 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | 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 |
@@ -442,6 +443,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) |
From 76c47905e6afd0e574ad92cd59d9d32ef2b0884f Mon Sep 17 00:00:00 2001 From: HoangJames Date: Wed, 28 Oct 2020 16:11:11 +0000 Subject: [PATCH 081/157] Find-The-Difference Problem Pull Req (#129) * added c++ solution for Find-The-Difference problem * Added Find The Difference problem to README Added Find The Difference problem to the Hashtable section --- C++/Find-The-Difference.cpp | 42 +++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 43 insertions(+) create mode 100644 C++/Find-The-Difference.cpp 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/README.md b/README.md index 7228bc36..2b6cf52e 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
From 413fd019d6a1d96e5d801171241bde9ae861de9b Mon Sep 17 00:00:00 2001 From: Pandz18 <58665834+Pandz18@users.noreply.github.com> Date: Wed, 28 Oct 2020 21:44:37 +0530 Subject: [PATCH 082/157] Create Permutations solution (#124) * Create Perm_Recus.java * Update Perm_Recus.java * Updated Co-authored-by: Gourav Rusiya --- Java/Perm_Recus.java | 32 ++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Java/Perm_Recus.java diff --git a/Java/Perm_Recus.java b/Java/Perm_Recus.java new file mode 100644 index 00000000..40b3a9a6 --- /dev/null +++ b/Java/Perm_Recus.java @@ -0,0 +1,32 @@ +public List> 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 189 | [Rotate-Array](https://leetcode.com/problems/rotate-array/) | [Python](./Python/rotate-array.py) | O(N) | O(1) | Medium | Array | | 496 | [next-greater-element-i](https://leetcode.com/problems/next-greater-element-i) | [Python](./Python/496_nextgreaterelement.py) | O(N) | O(1) | Medium | Array | | 1470 | [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array) | [Java](./Java/shuffle-the-array.java) | O(N) | O(1) | Easy | Array | +| 124 | [Permutation by Recussion](https://leetcode.com/problems/permutations/) | [Java](./Java/shuffle-the-array.java) | O(N) | O(N) | Easy | Array | | 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 | -
⬆️ Back to Top From f0e31908a22baaa1d1f8a405224640026f063cc4 Mon Sep 17 00:00:00 2001 From: Francode007 <63102937+Francode007@users.noreply.github.com> Date: Thu, 29 Oct 2020 14:57:39 +0530 Subject: [PATCH 083/157] K-Closest-Points-to-Origin in C++ (#131) * Added solution in c++ for #973 * Added name and details in Contributors * Update README.md * Update README.md * Update README.md * Update README.md * Added Solution to 3 Sum problem in C++ * Update README.md * Delete 3sum.cpp * Update README.md --- C++/k-closest-points-to-origin.cpp | 24 ++++++++++++++++++++++++ README.md | 16 ++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 C++/k-closest-points-to-origin.cpp 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 [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 | @@ -409,7 +421,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if ## Authors -- | [Gourav Rusiya](https://github.com/GouravRusiya30/)
+* | [Gourav Rusiya](https://github.com/GouravRusiya30/)

@@ -445,7 +457,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) |
⬆️ Back to Top From b21c5465cf3d42eed0d8c679811d59ed806d00bd Mon Sep 17 00:00:00 2001 From: Saurav Prateek Date: Thu, 29 Oct 2020 15:33:34 +0530 Subject: [PATCH 084/157] Adding solution of Arithmetic Subarrays (#130) * Added solution for Arithmetic Subarrays * added solution summary for the problem * formatting solution summary --- Java/arithmetic-subarrays.java | 69 ++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 70 insertions(+) create mode 100644 Java/arithmetic-subarrays.java diff --git a/Java/arithmetic-subarrays.java b/Java/arithmetic-subarrays.java new file mode 100644 index 00000000..1797d7f6 --- /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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | | 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | | 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | | +| 14 | [Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/) | [Java](./Java/arithmetic-subarrays.java) | _O(m*n)_ | _O(n)_ | Medium | Math | Pattern Count |
From 94f7e7bac65eecc2a0c4631e1ab18153b1de810e Mon Sep 17 00:00:00 2001 From: Francode007 <63102937+Francode007@users.noreply.github.com> Date: Thu, 29 Oct 2020 19:44:15 +0530 Subject: [PATCH 085/157] Adding Solution to 3 Sum in C++ (#132) * Added solution in c++ for #973 * Added name and details in Contributors * Update README.md * Update README.md * Update README.md * Update README.md * Added Solution to 3 Sum problem in C++ * Update README.md * Delete 3sum.cpp * Update README.md * Add files via upload * Update README.md --- C++/3sum.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 53 insertions(+) create mode 100644 C++/3sum.cpp diff --git a/C++/3sum.cpp b/C++/3sum.cpp new file mode 100644 index 00000000..8ee7c0dc --- /dev/null +++ b/C++/3sum.cpp @@ -0,0 +1,51 @@ +class Solution { +public: + vector> 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/README.md b/README.md index b5c7ad09..a199f025 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +
From b56d76bd1b95005022a2eeb6dd476023abf0f029 Mon Sep 17 00:00:00 2001 From: Saurav Prateek Date: Fri, 30 Oct 2020 09:32:04 +0530 Subject: [PATCH 086/157] Added a Leetcode solution for Valid Sudoku (#134) --- Java/valid-sudoku.java | 76 ++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 77 insertions(+) create mode 100644 Java/valid-sudoku.java 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
⬆️ Back to Top From 41418f6eb68e9fc910d5567cbda7877358749a54 Mon Sep 17 00:00:00 2001 From: Francode007 <63102937+Francode007@users.noreply.github.com> Date: Fri, 30 Oct 2020 09:33:12 +0530 Subject: [PATCH 087/157] Asteroid Collision in C++ solution (#133) * Added solution in c++ for #973 * Added name and details in Contributors * Update README.md * Update README.md * Update README.md * Update README.md * Added Solution to 3 Sum problem in C++ * Update README.md * Delete 3sum.cpp * Update README.md * Add files via upload * Update README.md * Add files via upload * Update README.md --- C++/asteroid-collision.cpp | 57 ++++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 58 insertions(+) create mode 100644 C++/asteroid-collision.cpp diff --git a/C++/asteroid-collision.cpp b/C++/asteroid-collision.cpp new file mode 100644 index 00000000..5eb3f7ca --- /dev/null +++ b/C++/asteroid-collision.cpp @@ -0,0 +1,57 @@ +class Solution { +public: + vector 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/README.md b/README.md index b6d63614..a8da07ec 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
From eecf894817b3c7b785ac11b0d0d7e3d60d964e01 Mon Sep 17 00:00:00 2001 From: Francode007 <63102937+Francode007@users.noreply.github.com> Date: Fri, 30 Oct 2020 15:06:17 +0530 Subject: [PATCH 088/157] Added solution to Decode String in C++ (#135) * Added solution in c++ for #973 * Added name and details in Contributors * Update README.md * Update README.md * Update README.md * Update README.md * Added Solution to 3 Sum problem in C++ * Update README.md * Delete 3sum.cpp * Update README.md * Add files via upload * Update README.md * Add files via upload * Update README.md * Add files via upload * Update README.md --- C++/decode-string.cpp | 32 ++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 33 insertions(+) create mode 100644 C++/decode-string.cpp 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/README.md b/README.md index a8da07ec..46349db4 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
From d88c5d2a0ea16aab093cfa72cc9bc84d9b6df6bd Mon Sep 17 00:00:00 2001 From: Saurav Prateek Date: Sat, 31 Oct 2020 09:35:20 +0530 Subject: [PATCH 089/157] Adding the solution for Redundant Connection (#136) * Added a Leetcode solution for Valid Sudoku * Added Solution code and Editorial-readme * Added problem in readme * Added editorial for the problem * Added image for editorial * Added editorial Image --- Java/Redundant-Connection/README.md | 39 ++++++++++++ Java/Redundant-Connection/images/image-1.png | Bin 0 -> 41284 bytes .../redundant-connection.java | 59 ++++++++++++++++++ README.md | 1 + 4 files changed, 99 insertions(+) create mode 100644 Java/Redundant-Connection/README.md create mode 100644 Java/Redundant-Connection/images/image-1.png create mode 100644 Java/Redundant-Connection/redundant-connection.java diff --git a/Java/Redundant-Connection/README.md b/Java/Redundant-Connection/README.md new file mode 100644 index 00000000..b178111b --- /dev/null +++ b/Java/Redundant-Connection/README.md @@ -0,0 +1,39 @@ +# Redundant Connection + +> **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 0000000000000000000000000000000000000000..840f02d9e1fed736ad5bfd8fc7663443b53d21fe GIT binary patch literal 41284 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 Cq(!X& literal 0 HcmV?d00001 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 1028 | [Recover a Tree From Preorder Traversal](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/) | [C++](./C++/Recover-a-Tree-From-Preorder-Traversal.cpp) | _O(n)_ | _O(n)_ | Hard | Tree | | | 968 | [Binary Tree Cameras](https://leetcode.com/problems/binary-tree-cameras/) | [C++](./C++/Binary-Tree-Cameras.cpp) | _O(n)_ | _O(logn)_ | Hard | Binary Tree, Dynamic Programming | | 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/) | [Javascript](./JavaScript/98.Validate-Binary-Search-Tree.js) | _O(log(n))_ | _O(log(n))_ | Medium | Binary Tree | +| 684 | [Redundant Connection](https://leetcode.com/problems/redundant-connection/) | [Java](./Java/Redundant-Connection/redundant-connection.java) | _O(N)_ | _O(N)_ | Medium | Tree, Union Find |
From 2602edf37a65dee27c4b04b13849a022eebd7016 Mon Sep 17 00:00:00 2001 From: MorviBhojwani <32567706+MorviBhojwani@users.noreply.github.com> Date: Tue, 3 Nov 2020 08:54:20 +0530 Subject: [PATCH 090/157] Solved Network Delay Time (#137) --- C++/Network-delay-time.cpp.txt | 19 +++++++++++++++++++ README.md | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 C++/Network-delay-time.cpp.txt diff --git a/C++/Network-delay-time.cpp.txt b/C++/Network-delay-time.cpp.txt new file mode 100644 index 00000000..b3e8bb95 --- /dev/null +++ b/C++/Network-delay-time.cpp.txt @@ -0,0 +1,19 @@ +//Time complexity O(V+E) +//Space Complexity O(V) +class Solution { +public: + int networkDelayTime(vector>& 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/README.md b/README.md index e0b8f52c..521f699f 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands/) | [Java](./Java/NumberOfIslands.java) | O(R \* C) | O(R \* C) | Medium | BFS | | 127 | [Word Ladder](https://leetcode.com/problems/word-ladder/) | [Java](./Java/word-ladder.java) | O(N^2 \* M) | O(N \* M) | Medium | BFS | | 994 | [Rotten Oranges](https://leetcode.com/problems/rotting-oranges/) | [Python](./Python/994_Rotting_Oranges.py) | O(N \* M) | O(N \* M) | Medium | BFS | +| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time/) | [C++](./C++/Network-delay-time.cpp) | _O(V+E))_ | O(V) | Medium | BFS | +
From a6d24c531d5018f6b47ed37ce7d85700b5022d3a Mon Sep 17 00:00:00 2001 From: Matt <56481807+AnxietyMedicine@users.noreply.github.com> Date: Sun, 8 Nov 2020 01:39:04 -0500 Subject: [PATCH 091/157] Create Number-of-Good-Pairs.java & Update README.md (#138) * Create Number-of-Good-Pairs.java * Update README.md --- Java/Number-of-Good-Pairs.java | 14 ++++++++++++++ README.md | 1 + 2 files changed, 15 insertions(+) create mode 100644 Java/Number-of-Good-Pairs.java 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/README.md b/README.md index 521f699f..e1c23ea0 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
⬆️ Back to Top From ef70fc630198bc7cb5cff9d8954014fa8e4253d4 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sun, 8 Nov 2020 12:42:07 +0530 Subject: [PATCH 092/157] Create intersection-of-two-linked-lists.java --- Java/intersection-of-two-linked-lists.java | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Java/intersection-of-two-linked-lists.java 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; + } +} From 9c3e30991c73f3112ad10b8d0e22b120f1c38192 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sun, 8 Nov 2020 12:46:10 +0530 Subject: [PATCH 093/157] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1c23ea0..4bf66a57 100644 --- a/README.md +++ b/README.md @@ -171,12 +171,14 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | --- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ---------- | ------ | ---------- | ------------------ | ---- | | 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 | | | 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 | | -| 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 | | +
From f857240d8b1880a2f613d69ee8f4d1d5258b8f96 Mon Sep 17 00:00:00 2001 From: JeongDaHyeon <48541114+JeongDaHyeon@users.noreply.github.com> Date: Tue, 17 Nov 2020 16:17:51 +0900 Subject: [PATCH 094/157] Rename add-two-numbers.java to Add-Two-Numbers.java (#140) Java file name begins with a capital letter. --- Java/{add-two-numbers.java => Add-Two-Numbers.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Java/{add-two-numbers.java => Add-Two-Numbers.java} (100%) 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 From 7aa77fcf6bdf3ce562dd667dc4b8f68c1a527f95 Mon Sep 17 00:00:00 2001 From: TOMATOMA <44044134+sujin0529@users.noreply.github.com> Date: Tue, 17 Nov 2020 16:18:33 +0900 Subject: [PATCH 095/157] Create Palindrome-number.java and Updated README.md (#139) * update README file with Palindrome-number problem * create palindrome-number.java * update README file with Path-Sum problem * create path-sum.java --- Java/palindrome-number.java | 19 ++++++++++++++++++ Java/path-sum.java | 40 +++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 3 files changed, 61 insertions(+) create mode 100644 Java/palindrome-number.java create mode 100644 Java/path-sum.java 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/README.md b/README.md index 4bf66a57..eb7e9551 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Java](./Java/max-nesting-depth-parentheses.java) | _O(n)_ | _O(1)_ | Easy | | | | 1374 | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | [Java](./Java/generate-a-string-with-characters-that-have-odd-counts.java) | _O(n)_ | _O(1)_ | Easy | | | | 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | |
⬆️ Back to Top @@ -327,6 +328,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | ---- | ------------------------------------------------------------------------------------------- | -------------------------------------------------- | ----------- | ----------- | ---------- | --- | ---- | | 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 | |
From ce7ca13046dd6053f71507b579e09fc910a01160 Mon Sep 17 00:00:00 2001 From: TOMATOMA <44044134+sujin0529@users.noreply.github.com> Date: Mon, 23 Nov 2020 16:20:43 +0900 Subject: [PATCH 096/157] Create same-tree.java and Updated README.md (#143) * update README file with Same-Tree problem * create same-tree.java * change file name to Same-Tree.java * change file name to Same-Tree.java * modify link to Same-Tree.java --- Java/Same-Tree.java | 42 ++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Java/Same-Tree.java diff --git a/Java/Same-Tree.java b/Java/Same-Tree.java new file mode 100644 index 00000000..7c3baebe --- /dev/null +++ b/Java/Same-Tree.java @@ -0,0 +1,42 @@ +/** + * 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 isSameTree(TreeNode p, TreeNode q) { + if (p == null && q == null) { + return true; + } + else if (p == null) { + return false; + } + else if (q == null) { + return false; + } + else { + if (p.val != q.val) { + return false; + } + else { + boolean left = isSameTree(p.left, q.left); + boolean right = isSameTree(p.right, q.right); + + return left && right; + } + } + } +} + diff --git a/README.md b/README.md index eb7e9551..fe4ebd90 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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) | _O(n)_ | _O(n)_ | Easy | Tree, Depth-first Search | | +| 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 | | From 91250184078b4bc718f8b121f30c2d27e2d5794b Mon Sep 17 00:00:00 2001 From: JeongDaHyeon <48541114+JeongDaHyeon@users.noreply.github.com> Date: Sat, 5 Dec 2020 20:33:54 +0900 Subject: [PATCH 097/157] Rename the Java files starting with a. (#145) * Rename arithmetic-subarrays.java to Arithmetic-Subarrays.java * Update README.md Update Arithmetic-Subarrays.java * Rename armstrong-number.java to Armstrong-Number.java * Update README.md Update Armstrong-Number.java * Update README.md Update Add-Two-Numbers --- ...{arithmetic-subarrays.java => Arithmetic-Subarrays.java} | 2 +- Java/{armstrong-number.java => Armstrong-Number.java} | 0 README.md | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) rename Java/{arithmetic-subarrays.java => Arithmetic-Subarrays.java} (99%) rename Java/{armstrong-number.java => Armstrong-Number.java} (100%) diff --git a/Java/arithmetic-subarrays.java b/Java/Arithmetic-Subarrays.java similarity index 99% rename from Java/arithmetic-subarrays.java rename to Java/Arithmetic-Subarrays.java index 1797d7f6..c5fdcca1 100644 --- a/Java/arithmetic-subarrays.java +++ b/Java/Arithmetic-Subarrays.java @@ -66,4 +66,4 @@ public List checkArithmeticSubarrays(int[] nums, int[] l, int[] r) { return res; } -} \ No newline at end of file +} diff --git a/Java/armstrong-number.java b/Java/Armstrong-Number.java similarity index 100% rename from Java/armstrong-number.java rename to Java/Armstrong-Number.java diff --git a/README.md b/README.md index fe4ebd90..7ede8df8 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | | +| 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 | | | @@ -170,7 +170,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | 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 | | +| 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 | | @@ -297,7 +297,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | | 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | | 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | | -| 14 | [Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/) | [Java](./Java/arithmetic-subarrays.java) | _O(m*n)_ | _O(n)_ | Medium | Math | Pattern Count | +| 14 | [Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/) | [Java](./Java/Arithmetic-Subarrays.java) | _O(m*n)_ | _O(n)_ | Medium | Math | Pattern Count |
From c5943dc6e3912e358101e2cecc9d25df7f9af829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=96=8C=EC=B1=A0?= Date: Sat, 5 Dec 2020 20:40:27 +0900 Subject: [PATCH 098/157] Add Solution of "minimum-add-to-make-parentheses-valid" & Update README.md (#146) --- C++/minimum-add-to-make-parentheses-valid.cpp | 29 +++++++++++++++++++ README.md | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 C++/minimum-add-to-make-parentheses-valid.cpp 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/README.md b/README.md index 7ede8df8..bfe7cc23 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Python](./Python/binary-tree-inorder-traversal.py) | _O(n)_ | _O(n)_ | Medium | Recursion, Binary Tree | | 735 | [Asteroid Collision](https://leetcode.com/problems/asteroid-collision/) | [C++](./C++/asteroid-collision.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | | 394 | [Decode String](https://leetcode.com/problems/decode-string/) | [C++](./C++/decode-string.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | +| 921 | [Minimum Add to Make Parentheses Valid](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) | [C++](./C++/minimum-add-to-make-parentheses-valid.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | |
@@ -472,6 +473,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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/) |
⬆️ Back to Top From 9be52053eec9b125abe0bddca645318d68bb0fea Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 5 Dec 2020 20:07:32 +0530 Subject: [PATCH 099/157] Create Search-a-2d-matrix.java --- Java/Search-a-2d-matrix.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Java/Search-a-2d-matrix.java diff --git a/Java/Search-a-2d-matrix.java b/Java/Search-a-2d-matrix.java new file mode 100644 index 00000000..c903a974 --- /dev/null +++ b/Java/Search-a-2d-matrix.java @@ -0,0 +1,29 @@ +class Solution { + public boolean searchMatrix(int[][] matrix, int target) { + + if(matrix.length == 0 || matrix[0].length == 0){ + return false; + } + + if(matrix[matrix.length-1][matrix[0].length-1] < target){ + return false; + } + + for(int i=0; i target){ + return false; + } + else if(matrix[i][j] == target){ + return true; + } + else{ + continue; + } + } + } + + return false; + } +} From b804bc7429a826d211ad53272869ce7c0e346cd8 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 5 Dec 2020 20:17:57 +0530 Subject: [PATCH 100/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bfe7cc23..d487d4e9 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ ![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/6sHPkUTC) [![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) From 524a94ff61c304c77fa917f25a93c9720c8b9e9c Mon Sep 17 00:00:00 2001 From: TOMATOMA <44044134+sujin0529@users.noreply.github.com> Date: Sat, 12 Dec 2020 16:08:34 +0900 Subject: [PATCH 101/157] Create Balanced-Binary-Tree.java and Updated README.md (#148) * README file with Balanced-Binary-Tree problem * create Balanced-Binary-Tree.java --- Java/Balanced-Binary-Tree.java | 46 ++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 47 insertions(+) create mode 100644 Java/Balanced-Binary-Tree.java diff --git a/Java/Balanced-Binary-Tree.java b/Java/Balanced-Binary-Tree.java new file mode 100644 index 00000000..2c6151ae --- /dev/null +++ b/Java/Balanced-Binary-Tree.java @@ -0,0 +1,46 @@ +/** + * 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 isBalanced(TreeNode root) { + + if(root==null){ + return true; + } + else{ + int left = height(root.left); + int right = height(root.right); + int diff = left - right; + diff = diff > 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/README.md b/README.md index d487d4e9..55aa86bd 100644 --- a/README.md +++ b/README.md @@ -330,6 +330,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
From 668662747cc14b80289a05d84a18b5d12dee33ab Mon Sep 17 00:00:00 2001 From: Gamez0 <34051876+Gamez0@users.noreply.github.com> Date: Tue, 15 Dec 2020 20:51:04 +0900 Subject: [PATCH 102/157] Add python code for 32 Longest Valid Parentheses & Update README.md (#150) --- Python/longest-valid-parentheses.py | 20 ++++++++++++++++++++ README.md | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Python/longest-valid-parentheses.py 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/README.md b/README.md index 55aa86bd..2b5ce843 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
⬆️ Back to Top @@ -475,6 +475,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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/) |
⬆️ Back to Top From a282cb8e0a5cb70a9b0a2780dcabdc17c8eaa016 Mon Sep 17 00:00:00 2001 From: JeongDaHyeon <48541114+JeongDaHyeon@users.noreply.github.com> Date: Mon, 21 Dec 2020 01:12:11 +0900 Subject: [PATCH 103/157] Create Ugly-Number.java and Updated README.md (#152) * Create Ugly-Number.java * Update README.md --- Java/Ugly-Number.java | 23 +++++++++++++++++++++++ README.md | 4 ++++ 2 files changed, 27 insertions(+) create mode 100644 Java/Ugly-Number.java 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/README.md b/README.md index 2b5ce843..9de6e5f1 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | | 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | | | 14 | [Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/) | [Java](./Java/Arithmetic-Subarrays.java) | _O(m*n)_ | _O(n)_ | Medium | Math | Pattern Count | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number/) | [Java](./Java/Ugly-Number.java) | _O(n)_ | _O(n)_ | Easy | Math | | + +
@@ -476,6 +479,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) |
⬆️ Back to Top From 5cdac14ee12fb2d70fecb3e5343f9940119afe0f Mon Sep 17 00:00:00 2001 From: YAMCHA Date: Mon, 21 Dec 2020 01:14:05 +0900 Subject: [PATCH 104/157] Add C++ Solution of "minimum-remove-to-make-valid-parentheses" & Update README.md (#153) * Update README.md * Create minimum-remove-to-make-valid-parentheses.cpp * edit wrong filename --- ...ay-time.cpp.txt => Network-delay-time.cpp} | 0 ...nimum-remove-to-make-valid-parentheses.cpp | 35 +++++++++++++++++++ README.md | 1 + 3 files changed, 36 insertions(+) rename C++/{Network-delay-time.cpp.txt => Network-delay-time.cpp} (100%) create mode 100644 C++/minimum-remove-to-make-valid-parentheses.cpp diff --git a/C++/Network-delay-time.cpp.txt b/C++/Network-delay-time.cpp similarity index 100% rename from C++/Network-delay-time.cpp.txt rename to C++/Network-delay-time.cpp 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/README.md b/README.md index 9de6e5f1..e455cc8c 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
⬆️ Back to Top From e52d443d55096987ca84c561c2a5930c237ac00b Mon Sep 17 00:00:00 2001 From: Gamez0 <34051876+Gamez0@users.noreply.github.com> Date: Tue, 29 Dec 2020 15:57:55 +0900 Subject: [PATCH 105/157] Add reorganize-string.py & Updated README.md (#154) --- Python/reorganize-string.py | 26 ++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 27 insertions(+) create mode 100644 Python/reorganize-string.py 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/README.md b/README.md index e455cc8c..33b728ed 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 1374 | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | [Java](./Java/generate-a-string-with-characters-that-have-odd-counts.java) | _O(n)_ | _O(1)_ | Easy | | | | 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | | | 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | | +| 767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./Python/reorganize-string.py) | _O(n)_ | _O(n)_ | Medium | | |
⬆️ Back to Top From 8e05ce57f6963d792d69adb3f776b58d8bec496c Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 30 Dec 2020 15:19:15 +0530 Subject: [PATCH 106/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 33b728ed..7a975327 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ ![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/6sHPkUTC) +[![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) From e92b38c3296056986b90afe8029535c4ceca478e Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Mon, 4 Jan 2021 11:32:31 +0530 Subject: [PATCH 107/157] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a975327..f53ccb34 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Linked List -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| # | 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 | | @@ -178,7 +178,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 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 | | From 912d72f420d3c6d53fe0e4deb5359c0b00b8bb42 Mon Sep 17 00:00:00 2001 From: Aysia <70167431+aysiae@users.noreply.github.com> Date: Thu, 4 Mar 2021 09:02:43 -0800 Subject: [PATCH 108/157] Min depth (#157) * min depth of binary tree * added comments, updated readme --- .../111-minimum-depth-of-binary-tree.js | 56 +++++++++++++++++++ README.md | 6 +- 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 JavaScript/111-minimum-depth-of-binary-tree.js diff --git a/JavaScript/111-minimum-depth-of-binary-tree.js b/JavaScript/111-minimum-depth-of-binary-tree.js new file mode 100644 index 00000000..244990cd --- /dev/null +++ b/JavaScript/111-minimum-depth-of-binary-tree.js @@ -0,0 +1,56 @@ +/** + * Definition for a binary tree node. + * function TreeNode(val, left, right) { + * this.val = (val===undefined ? 0 : val) + * this.left = (left===undefined ? null : left) + * this.right = (right===undefined ? null : right) + * } + */ +/** + * @param {TreeNode} root + * @return {number} + */ + +// PROBLEM: +// Given a binary tree, find its minimum depth. +// The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. + + // test cases: + // [3,9,20,null,null,15,7] -- output: 2 +// [2,null,3,null,4,null,5,null,6] -- output: 5 +// [0] -- output: 1 +// [] -- output: 0 + + +var minDepth = function(root) { + if(root) { + return traversal(root, 1); + } else { return 0 } +}; + +// traversal of the tree is recursive to ensure travel down +// both the right and left children nodes +var traversal = (root, depth) => { + 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/README.md b/README.md index f53ccb34..93cbe376 100644 --- a/README.md +++ b/README.md @@ -320,8 +320,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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
⬆️ Back to Top @@ -481,7 +480,8 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) | +| [JeongDaHyeon](https://github.com/JeongDaHyeon)
| South Korea | Java | [GitHub](https://github.com/JeongDaHyeon) | +[Aysia](https://www.linkedin.com/in/aysiaelise/) ![Hi](https://avatars.githubusercontent.com/u/70167431?s=460&u=1637be8636b6db6e35343ed9c1318c23e909b463&v=4) | USA | JavaScript | [GitHub](https://github.com/aysiae)
⬆️ Back to Top From c78319e4932f3772bf665e484cf85d05418029a3 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Thu, 4 Mar 2021 22:35:37 +0530 Subject: [PATCH 109/157] updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 93cbe376..9c0e12ff 100644 --- a/README.md +++ b/README.md @@ -481,7 +481,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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/) ![Hi](https://avatars.githubusercontent.com/u/70167431?s=460&u=1637be8636b6db6e35343ed9c1318c23e909b463&v=4) | USA | JavaScript | [GitHub](https://github.com/aysiae) +[Aysia](https://www.linkedin.com/in/aysiaelise/)
| USA | JavaScript | [GitHub](https://github.com/aysiae)
⬆️ Back to Top From 8a4487736a191e87eb6a9a2e6afb77eb3bc6ee33 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 24 Mar 2021 23:55:45 +0530 Subject: [PATCH 110/157] Set theme jekyll-theme-hacker From b37b4f2940ad8287ced62ec73cd6e9ad6489c931 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 24 Mar 2021 23:57:23 +0530 Subject: [PATCH 111/157] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9c0e12ff..0aa624dd 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ [![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/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) From 41a955458fcb80bcab3884827f8e55e7028d679b Mon Sep 17 00:00:00 2001 From: Poorvi Garg <68559217+POORVI111@users.noreply.github.com> Date: Mon, 12 Apr 2021 23:12:44 +0530 Subject: [PATCH 113/157] Time Needed to Inform All Employees - Depth First Search (#158) * Time needed to inform all employees Time needed to inform all employees - Depth First Search. * Update README.md --- C++/Time-Needed-To-Inform-All-Employees.cpp | 29 +++++++++++++++++++++ README.md | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 C++/Time-Needed-To-Inform-All-Employees.cpp 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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++] | _O(n)_ | _O(n)_ | Medium | DFS | | +|
From ca13ec7ad5470beeb27b45d6236110348ab1b702 Mon Sep 17 00:00:00 2001 From: Poorvi Garg <68559217+POORVI111@users.noreply.github.com> Date: Tue, 13 Apr 2021 12:26:51 +0530 Subject: [PATCH 114/157] Merge Two Sorted Lists - Two Pointer (#159) * Time needed to inform all employees Time needed to inform all employees - Depth First Search. * Update README.md * Added Merge Two Sorted Lists - Two Pointer * Updated Read Me --- C++/Merge-Two-Sorted-Lists.cpp | 41 ++++++++++++++++++++++++++++++++++ README.md | 8 ++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 C++/Merge-Two-Sorted-Lists.cpp diff --git a/C++/Merge-Two-Sorted-Lists.cpp b/C++/Merge-Two-Sorted-Lists.cpp new file mode 100644 index 00000000..8891df0c --- /dev/null +++ b/C++/Merge-Two-Sorted-Lists.cpp @@ -0,0 +1,41 @@ +// Time Complexity : O(n) +// Space Complexity : O(1) + + + +Problem: Merge two sorted Lists + + +/** + * 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* mergeTwoLists(ListNode* l1, ListNode* l2) { + if(l1 == NULL) + return l2; + if(l2 == NULL) + return l1; + + if(l1 -> val <= l2 -> val) + { + l1 -> next = mergeTwoLists(l1 -> next, l2); + return l1; + } + + else + { + l2 -> next = mergeTwoLists(l1, l2 -> next); + return l2; + } + } +}; + + diff --git a/README.md b/README.md index 434942b8..c5c513e3 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 4 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [Java](./Java/median-of-two-sorted-arrays.java) | _O(log(min(m,n)))_ | _O(1)_ | Hard | | | | 845 | [Longest Mountain in Array](https://leetcode.com/problems/longest-mountain-in-array/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | 015 | [3 Sum](https://leetcode.com/problems/3sum/) | [C++](./C++/3sum.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | +| 021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Easy | Two Pointer | |
@@ -335,7 +336,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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++] | _O(n)_ | _O(n)_ | Medium | 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 | | |
⬆️ Back to Top @@ -482,6 +483,11 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) + + + +
⬆️ Back to Top From b9c205f2d5dae8054cc67abfdec9e501c9e34eba Mon Sep 17 00:00:00 2001 From: Lakshmanan Meiyappan Date: Fri, 16 Apr 2021 00:36:54 -0500 Subject: [PATCH 115/157] Bit Manipulation C++ Solutions (#160) * Add C++ Solutions for Bit Manipulation * Update README.md --- C++/Detect-Capital.cpp | 19 +++++++++++++++++++ C++/Number-Complement.cpp | 20 ++++++++++++++++++++ C++/Single-Number-II.cpp | 17 +++++++++++++++++ C++/Single-Number-III.cpp | 36 ++++++++++++++++++++++++++++++++++++ README.md | 9 +++++---- 5 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 C++/Detect-Capital.cpp create mode 100644 C++/Number-Complement.cpp create mode 100644 C++/Single-Number-II.cpp create mode 100644 C++/Single-Number-III.cpp 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& 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/README.md b/README.md index c5c513e3..bf89f49f 100644 --- a/README.md +++ b/README.md @@ -83,10 +83,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | | ---- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | | 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java)
[Python](./Python/single-number.py)
[C++](./C++/Single-Number.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR | -| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py) | _O(n)_ | _O(1)_ | Medium | | | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _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) | _O(n)_ | _O(1)_ | Easy | | | +| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py)
[C++](./C++/Single-Number-II.cpp) | _O(n)_ | _O(1)_ | Medium | | | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py)
[C++](./C++/Single-Number-III.cpp) | _O(n)_ | _O(1)_ | Medium | | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java)
[C++](./C++/Number-Complement.cpp) | _O(1)_ | _O(1)_ | Easy | | [Tutorial](https://youtu.be/6bp5V-O3zts) | +| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py)
[C++](./C++/Detect-Capital.cpp) | _O(n)_ | _O(1)_ | Easy | | | | 1486 | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) | [Java](./Java/xor-op-in-array.java) | _O(n)_ | _O(1)_ | Easy | | Using XOR |
@@ -484,6 +484,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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/) From 1745d8f81a167ebd211bbe16304acd779f70de36 Mon Sep 17 00:00:00 2001 From: garvitdoda1266 <61387258+garvitdoda1266@users.noreply.github.com> Date: Mon, 26 Apr 2021 23:31:41 +0530 Subject: [PATCH 116/157] improved c++ code (#161) --- C++/two-sum.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/C++/two-sum.cpp b/C++/two-sum.cpp index 98ec9a93..c562d2ea 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; + } +} +} \ No newline at end of file From 571ef25d7179191f325bbe06c1595d37274d0ad1 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Mon, 26 Apr 2021 23:33:04 +0530 Subject: [PATCH 117/157] Update two-sum.cpp --- C++/two-sum.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/C++/two-sum.cpp b/C++/two-sum.cpp index c562d2ea..a6489044 100644 --- a/C++/two-sum.cpp +++ b/C++/two-sum.cpp @@ -16,7 +16,7 @@ class Solution { } }; -Above solution is of O(n^2) time complexity +// Above solution is of O(n^2) time complexity //O(n) time complexity //O(n) space complexity @@ -38,4 +38,4 @@ vector twoSum(vector &numbers, int target) return finalresult; } } -} \ No newline at end of file +} From 50b5fb10b6cc4480d1648aeb64767142cc0ca02c Mon Sep 17 00:00:00 2001 From: Rohinsri <61387189+Rohinsri@users.noreply.github.com> Date: Tue, 27 Apr 2021 09:30:28 +0530 Subject: [PATCH 118/157] Helped optimise the code (#162) --- C++/brick-wall.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 From d3e4d25c3e646b45cf48e5413cc7e53324240a24 Mon Sep 17 00:00:00 2001 From: "G@rv!T" <61387258+garvitdoda1266@users.noreply.github.com> Date: Fri, 30 Apr 2021 14:01:33 +0530 Subject: [PATCH 119/157] Remove-Covered-Intervals.cpp (#163) * improved c++ code * Improved code with O(nlogn) solution Co-authored-by: Gourav Rusiya --- C++/Remove-Covered-Intervals.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/C++/Remove-Covered-Intervals.cpp b/C++/Remove-Covered-Intervals.cpp index 28de473f..52808d2d 100644 --- a/C++/Remove-Covered-Intervals.cpp +++ b/C++/Remove-Covered-Intervals.cpp @@ -27,3 +27,32 @@ class Solution { }; //Complexity: O(n*n) + + + +SIMPLIFIED SOLUTION in O(nlogn) time + +// +class Solution { +public: + int removeCoveredIntervals(vector>& intervals) { + sort(intervals.begin(),intervals.end(),[](vector& v1,vector& v2){ + if(v1[0]==v2[0]) + return v1[1]>v2[1]; + return v1[0]end) + { + end = intervals[i][1]; + sz++; + } + } + return sz; + } +}; + +// From b94a0e6fc341da2e3e6bb858165cd9f5e751c876 Mon Sep 17 00:00:00 2001 From: Jasbir Rajrana <68157847+jasbirrajrana@users.noreply.github.com> Date: Mon, 17 May 2021 14:18:44 +0530 Subject: [PATCH 120/157] ADD: 162-Leetcode(Find Peak element) (#166) * ADD: 162-Leetcode(Find Peak element) * fix: Graph Portion in Readme.md file --- JavaScript/findPeakElement.js | 31 +++++ README.md | 219 +++++++++++++++++----------------- 2 files changed, 141 insertions(+), 109 deletions(-) create mode 100644 JavaScript/findPeakElement.js 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/README.md b/README.md index bf89f49f..58325e67 100644 --- a/README.md +++ b/README.md @@ -83,10 +83,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | | ---- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | | 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java)
[Python](./Python/single-number.py)
[C++](./C++/Single-Number.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR | -| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py)
[C++](./C++/Single-Number-II.cpp) | _O(n)_ | _O(1)_ | Medium | | | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py)
[C++](./C++/Single-Number-III.cpp) | _O(n)_ | _O(1)_ | Medium | | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java)
[C++](./C++/Number-Complement.cpp) | _O(1)_ | _O(1)_ | Easy | | [Tutorial](https://youtu.be/6bp5V-O3zts) | -| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py)
[C++](./C++/Detect-Capital.cpp) | _O(n)_ | _O(1)_ | Easy | | | +| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py)
[C++](./C++/Single-Number-II.cpp) | _O(n)_ | _O(1)_ | Medium | | | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py)
[C++](./C++/Single-Number-III.cpp) | _O(n)_ | _O(1)_ | Medium | | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java)
[C++](./C++/Number-Complement.cpp) | _O(1)_ | _O(1)_ | Easy | | [Tutorial](https://youtu.be/6bp5V-O3zts) | +| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py)
[C++](./C++/Detect-Capital.cpp) | _O(n)_ | _O(1)_ | Easy | | | | 1486 | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) | [Java](./Java/xor-op-in-array.java) | _O(n)_ | _O(1)_ | Easy | | Using XOR |
@@ -97,9 +97,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Sort -| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | -| ---- | --------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | -| 973 | [K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin/) | [C++](./C++/k-closest-points-to-origin.cpp) | _O(n)_ | _O(1)_ | Medium | | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | +| --- | --------------------------------------------------------------------------------------- | ------------------------------------------- | ------ | ------ | ---------- | --- | -------- | +| 973 | [K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin/) | [C++](./C++/k-closest-points-to-origin.cpp) | _O(n)_ | _O(1)_ | Medium | | |
@@ -136,12 +136,15 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 189 | [Rotate-Array](https://leetcode.com/problems/rotate-array/) | [Python](./Python/rotate-array.py) | O(N) | O(1) | Medium | Array | | 496 | [next-greater-element-i](https://leetcode.com/problems/next-greater-element-i) | [Python](./Python/496_nextgreaterelement.py) | O(N) | O(1) | Medium | Array | | 1470 | [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array) | [Java](./Java/shuffle-the-array.java) | O(N) | O(1) | Easy | Array | -| 124 | [Permutation by Recussion](https://leetcode.com/problems/permutations/) | [Java](./Java/shuffle-the-array.java) | O(N) | O(N) | Easy | Array | +| 124 | [Permutation by Recussion](https://leetcode.com/problems/permutations/) | [Java](./Java/shuffle-the-array.java) | O(N) | O(N) | Easy | Array | | 283 | [Move-Zeroes](https://leetcode.com/problems/move-zeroes/) | [C++](./C++/Move-Zeroes.cpp) | O(N) | O(1) | Easy | Array | -| 27 | [Remove-Element](https://leetcode.com/problems/remove-element/) | [C++](./C++/remove-element.cpp) | O(N) | O(1) | Easy | Array | -| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku/) | [Java](./Java/valid-sudoku.java) | O(N^2) | O(N) | Medium | Array, 2D Matrix | -| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/) | [Java](./Java/Number-of-Good-Pairs.java) | O(N^2) | O(1) | Easy | Array | +| 27 | [Remove-Element](https://leetcode.com/problems/remove-element/) | [C++](./C++/remove-element.cpp) | O(N) | O(1) | Easy | Array | +| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku/) | [Java](./Java/valid-sudoku.java) | O(N^2) | O(N) | Medium | Array, 2D Matrix | +| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/) | [Java](./Java/Number-of-Good-Pairs.java) | O(N^2) | O(1) | Easy | Array | +| 162 | [Find Peak element](https://leetcode.com/problems/find-peak-element/) | [javascript](./javascript/findPeakElement.js) | o(Logn) | O(1) | Medium | Array | +
+ @@ -158,9 +161,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 1221 | [Split a String in Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings/) | [Python](./Python/split-a-string-in-balanced-strings.py) | _O(n)_ | _O(1)_ | Easy | | | | 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Java](./Java/max-nesting-depth-parentheses.java) | _O(n)_ | _O(1)_ | Easy | | | | 1374 | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | [Java](./Java/generate-a-string-with-characters-that-have-odd-counts.java) | _O(n)_ | _O(1)_ | Easy | | | -| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | | -| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | | -| 767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./Python/reorganize-string.py) | _O(n)_ | _O(n)_ | Medium | | | +| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | | +| 767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./Python/reorganize-string.py) | _O(n)_ | _O(n)_ | Medium | | | +
⬆️ Back to Top @@ -169,18 +173,17 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Linked List -| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | -| --- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ---------- | ------ | ---------- | ------------------ | ---- | -| 002 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [Java](./Java/Add-Two-Numbers.java) | _O(n)_ | _O(n)_ | Medium | Math | | -| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) | [Java](./Java/remove-nth-node-from-end-of-list.java) | _O(n)_ | _O(1)_ | Medium | Two pointers | | -| 23 | [Merge K sorted lists](https://leetcode.com/problems/merge-k-sorted-lists/) | [C++](./C++/merge-k-sorted-lists.cpp) | _O(nlogn)_ | _O(n)_ | Hard | sorting and append | | -| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/) | [Java](./Java/convert-sorted-list-to-binary-search-tree.java) | _O(n)_ | _O(n)_ | Medium | LinkedList | | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/) | [Java](./Java/linked-list-cycle.java) | _O(n)_ | _O(1)_ | Easy | Slow-Fast Pointers | | -| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/) | [Java](./Java/linked-list-cycle-ii.java)
[C++](./C++/Linked-List-Cycle-II.cpp) | _O(n)_ | _O(1)_ | Medium | Slow-Fast Pointers | | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [C++](./C++/LRU-Cache.cpp)
[Python](./Python/LRUCache.py) | _O(1)_ | _O(k)_ | Medium | Hash Map | | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists/) | [Java](./Java/intersection-of-two-linked-lists.java) | _O(n)_ | _O(1)_ | Easy | Two Pointers | [Tutorial](https://youtu.be/uozGB0-gbvI) | -| 186 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/) | [Java](./Java/middle-of-the-linked-list.java) | _O(n)_ | _O(1)_ | Easy | Two pointers | | - +| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | +| --- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ---------- | ------ | ---------- | ------------------ | ---------------------------------------- | +| 002 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [Java](./Java/Add-Two-Numbers.java) | _O(n)_ | _O(n)_ | Medium | Math | | +| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) | [Java](./Java/remove-nth-node-from-end-of-list.java) | _O(n)_ | _O(1)_ | Medium | Two pointers | | +| 23 | [Merge K sorted lists](https://leetcode.com/problems/merge-k-sorted-lists/) | [C++](./C++/merge-k-sorted-lists.cpp) | _O(nlogn)_ | _O(n)_ | Hard | sorting and append | | +| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/) | [Java](./Java/convert-sorted-list-to-binary-search-tree.java) | _O(n)_ | _O(n)_ | Medium | LinkedList | | +| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/) | [Java](./Java/linked-list-cycle.java) | _O(n)_ | _O(1)_ | Easy | Slow-Fast Pointers | | +| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/) | [Java](./Java/linked-list-cycle-ii.java)
[C++](./C++/Linked-List-Cycle-II.cpp) | _O(n)_ | _O(1)_ | Medium | Slow-Fast Pointers | | +| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [C++](./C++/LRU-Cache.cpp)
[Python](./Python/LRUCache.py) | _O(1)_ | _O(k)_ | Medium | Hash Map | | +| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists/) | [Java](./Java/intersection-of-two-linked-lists.java) | _O(n)_ | _O(1)_ | Easy | Two Pointers | [Tutorial](https://youtu.be/uozGB0-gbvI) | +| 186 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/) | [Java](./Java/middle-of-the-linked-list.java) | _O(n)_ | _O(1)_ | Easy | Two pointers | |
@@ -202,9 +205,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Python](./Python/binary-tree-inorder-traversal.py) | _O(n)_ | _O(n)_ | Medium | Recursion, Binary Tree | | 735 | [Asteroid Collision](https://leetcode.com/problems/asteroid-collision/) | [C++](./C++/asteroid-collision.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | | 394 | [Decode String](https://leetcode.com/problems/decode-string/) | [C++](./C++/decode-string.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | -| 921 | [Minimum Add to Make Parentheses Valid](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) | [C++](./C++/minimum-add-to-make-parentheses-valid.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | -| 32 | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses/) | [Python](.Python/longest-valid-parentheses.py) | _O(n)_ | _O(n)_ | Hard | Stack | | -| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/) | [C++](./C++/minimum-remove-to-make-valid-parentheses.cpp) | _O(n)_ | _O(n)_ | Medium | Stack | | +| 921 | [Minimum Add to Make Parentheses Valid](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) | [C++](./C++/minimum-add-to-make-parentheses-valid.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | +| 32 | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses/) | [Python](.Python/longest-valid-parentheses.py) | _O(n)_ | _O(n)_ | Hard | Stack | | +| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/) | [C++](./C++/minimum-remove-to-make-valid-parentheses.cpp) | _O(n)_ | _O(n)_ | Medium | Stack | | +
⬆️ Back to Top @@ -243,7 +247,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 1028 | [Recover a Tree From Preorder Traversal](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/) | [C++](./C++/Recover-a-Tree-From-Preorder-Traversal.cpp) | _O(n)_ | _O(n)_ | Hard | Tree | | | 968 | [Binary Tree Cameras](https://leetcode.com/problems/binary-tree-cameras/) | [C++](./C++/Binary-Tree-Cameras.cpp) | _O(n)_ | _O(logn)_ | Hard | Binary Tree, Dynamic Programming | | 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/) | [Javascript](./JavaScript/98.Validate-Binary-Search-Tree.js) | _O(log(n))_ | _O(log(n))_ | Medium | Binary Tree | -| 684 | [Redundant Connection](https://leetcode.com/problems/redundant-connection/) | [Java](./Java/Redundant-Connection/redundant-connection.java) | _O(N)_ | _O(N)_ | Medium | Tree, Union Find | +| 684 | [Redundant Connection](https://leetcode.com/problems/redundant-connection/) | [Java](./Java/Redundant-Connection/redundant-connection.java) | _O(N)_ | _O(N)_ | Medium | Tree, Union Find |
@@ -253,17 +257,17 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Hash Table -| # | Title | Solution | Time | Space | Difficulty | Tag | Video Explanation | -| --- | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ----------- | ------ | ---------- | --- | ------------------------------------------------------- | -| 001 | [Two Sum](https://leetcode.com/problems/two-sum/) | [Java](./Java/two-sum.java)
[Python](./Python/1_TwoSum.py)
[C++](./C++/two-sum.cpp) | _O(N)_ | _O(N)_ | Easy | | [Tutorial](https://youtu.be/47xMuvwP7zQ) | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [Java](./Java/valid-anagram.java) | _O(n)_ | _O(1)_ | Easy | | [Tutorial](https://www.youtube.com/watch?v=sbX1Ze9lNQE) | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Java](./Java/LRU-Cache.java) | | | Medium | | | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | [Python](./Python/contains-duplicate.py) | _O(n)_ | _O(n)_ | | | -| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | -| 049 | [Group Anagrams](https://leetcode.com/problems/group-anagrams/) | [Python](./Python/group_anagram.py) | _O(nlogn)_ | _O(1)_ | Easy | | -| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Javascript](../JavaScript/146.LRU-Cache.js) | _O(log(n))_ | _O(n)_ | Medium | | -| 389 | [Find The Difference](https://leetcode.com/problems/find-the-difference/) | [C++](../C++/Find-The-Difference.cpp) | _O(n)_ | _O(1)_ | Easy | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Video Explanation | +| --- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ----------- | ------ | ---------- | --- | ------------------------------------------------------- | +| 001 | [Two Sum](https://leetcode.com/problems/two-sum/) | [Java](./Java/two-sum.java)
[Python](./Python/1_TwoSum.py)
[C++](./C++/two-sum.cpp) | _O(N)_ | _O(N)_ | Easy | | [Tutorial](https://youtu.be/47xMuvwP7zQ) | +| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [Java](./Java/valid-anagram.java) | _O(n)_ | _O(1)_ | Easy | | [Tutorial](https://www.youtube.com/watch?v=sbX1Ze9lNQE) | +| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Java](./Java/LRU-Cache.java) | | | Medium | | | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | [Python](./Python/contains-duplicate.py) | _O(n)_ | _O(n)_ | | | +| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | +| 049 | [Group Anagrams](https://leetcode.com/problems/group-anagrams/) | [Python](./Python/group_anagram.py) | _O(nlogn)_ | _O(1)_ | Easy | | +| 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | +| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Javascript](../JavaScript/146.LRU-Cache.js) | _O(log(n))_ | _O(n)_ | Medium | | +| 389 | [Find The Difference](https://leetcode.com/problems/find-the-difference/) | [C++](../C++/Find-The-Difference.cpp) | _O(n)_ | _O(1)_ | Easy | |
@@ -279,8 +283,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 4 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [Java](./Java/median-of-two-sorted-arrays.java) | _O(log(min(m,n)))_ | _O(1)_ | Hard | | | | 845 | [Longest Mountain in Array](https://leetcode.com/problems/longest-mountain-in-array/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | 015 | [3 Sum](https://leetcode.com/problems/3sum/) | [C++](./C++/3sum.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | -| 021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Easy | Two Pointer | | - +| 021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Easy | Two Pointer | |
@@ -290,21 +293,19 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Math -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| --- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ----------------- | ------ | ---------- | ------ | ---- | -| 050 | [Pow(x, n)](https://leetcode.com/problems/powx-n/) | [Python](./Python/50.Powxn.py)
[JavaScript](./JavaScript/50.Powxn.js) | _O(n)_ | _O(1)_ | Medium | Math | | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [C++](./C++/Count-Primes.cpp) | _O(n(log(logn)))_ | _O(n)_ | Easy | Math | | -| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/) | [C++](./C++/Excel-Sheet-Column-Number.cpp) | _O(n)_ | _O(1)_ | Easy | String | | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [C++](./C++/Excel-Sheet-Column-Title.cpp) | _O(n)_ | _O(n)_ | Easy | String | | -| 007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](./Java/reverse-integer.java)
[C++](./C++/Reverse-Integer.cpp) | _O(n)_ | _O(n)_ | Easy | Math | | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | -| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | -| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | | -| 14 | [Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/) | [Java](./Java/Arithmetic-Subarrays.java) | _O(m*n)_ | _O(n)_ | Medium | Math | Pattern Count | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number/) | [Java](./Java/Ugly-Number.java) | _O(n)_ | _O(n)_ | Easy | Math | | - - +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| --- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ----------------- | ------ | ---------- | ------ | ------------- | +| 050 | [Pow(x, n)](https://leetcode.com/problems/powx-n/) | [Python](./Python/50.Powxn.py)
[JavaScript](./JavaScript/50.Powxn.js) | _O(n)_ | _O(1)_ | Medium | Math | | +| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [C++](./C++/Count-Primes.cpp) | _O(n(log(logn)))_ | _O(n)_ | Easy | Math | | +| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/) | [C++](./C++/Excel-Sheet-Column-Number.cpp) | _O(n)_ | _O(1)_ | Easy | String | | +| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [C++](./C++/Excel-Sheet-Column-Title.cpp) | _O(n)_ | _O(n)_ | Easy | String | | +| 007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](./Java/reverse-integer.java)
[C++](./C++/Reverse-Integer.cpp) | _O(n)_ | _O(n)_ | Easy | Math | | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | +| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _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 | |
@@ -320,8 +321,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands/) | [Java](./Java/NumberOfIslands.java) | O(R \* C) | O(R \* C) | Medium | BFS | | 127 | [Word Ladder](https://leetcode.com/problems/word-ladder/) | [Java](./Java/word-ladder.java) | O(N^2 \* M) | O(N \* M) | Medium | BFS | | 994 | [Rotten Oranges](https://leetcode.com/problems/rotting-oranges/) | [Python](./Python/994_Rotting_Oranges.py) | O(N \* M) | O(N \* M) | Medium | BFS | -| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time/) | [C++](./C++/Network-delay-time.cpp) | _O(V+E))_ | O(V) | Medium | BFS | - 111 | [Min Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [JavaScript](./JavaScript/111-minimum-depth-of-binary-tree.js) | O(nlogn) | O(nlogn) | Easy | BFS +| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time/) | [C++](./C++/Network-delay-time.cpp) | _O(V+E))_ | O(V) | Medium | BFS | +| 111 | [Min Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [JavaScript](./JavaScript/111-minimum-depth-of-binary-tree.js) | O(nlogn) | O(nlogn) | Easy | BFS | +
⬆️ Back to Top @@ -330,14 +332,16 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # Depth-First Search -| # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | ------------------------------------------------------------------------------------------- | -------------------------------------------------- | ----------- | ----------- | ---------- | --- | ---- | -| 1463 | [Cherry Pickup II](https://leetcode.com/problems/cherry-pickup-ii/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n \* m)_ | _O(n \* m)_ | Hard | DFS | | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [python](./Python/maximum-depth-of-binary-tree.py) | _O(n)_ | _O(n)_ | Easy | DFS | | -| 112 | [Path Sum](https://leetcode.com/problems/path-sum/) | [Java](./Java/path-sum.java) | _O(n)_ | _O(n)_ | Easy | DFS | | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [Java](./Java/Balanced-Binary-Tree.java) | _O(n)_ | _O(n)_ | Easy | DFS | | -| 1376 | [ Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n)_ | _O(n)_ | Medium | DFS | | +| # | Title | Solution | Time | Space | Difficulty | Tag | Note | +| ---- | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | ----------- | ----------- | ---------- | --- | ---- | +| 1463 | [Cherry Pickup II](https://leetcode.com/problems/cherry-pickup-ii/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n \* m)_ | _O(n \* m)_ | Hard | DFS | | +| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [python](./Python/maximum-depth-of-binary-tree.py) | _O(n)_ | _O(n)_ | Easy | DFS | | +| 112 | [Path Sum](https://leetcode.com/problems/path-sum/) | [Java](./Java/path-sum.java) | _O(n)_ | _O(n)_ | Easy | DFS | | +| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [Java](./Java/Balanced-Binary-Tree.java) | _O(n)_ | _O(n)_ | Easy | DFS | | +| 1376 | [ Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n)_ | _O(n)_ | Medium | DFS | | + |
+ @@ -442,53 +446,50 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if ## Authors -* | [Gourav Rusiya](https://github.com/GouravRusiya30/)
+- | [Gourav Rusiya](https://github.com/GouravRusiya30/)

## Contributors -| Name | Country | Programming Language | Where to find you
(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...) | -| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [Gourav R](https://github.com/GouravRusiya30/)
| India | Java | [codedecks](https://www.youtube.com/c/codedecks/)
[Hackerrank](https://www.hackerrank.com/gouravrusiya786)
[LeetCode](https://leetcode.com/rusiya/) | -| [Dima Vishnevetsky](https://github.com/dimshik100)
| Israel | JavaScript | [Twitter](https://twitter.com/dimshik100)
[Facebook](https://www.facebook.com/dimshik) | -| [Anuj Sharma](https://github.com/Optider/)
| India | Python | [Github](https://github.com/Optider) | -| [Lokendra Bohra](https://github.com/lokendra1704/)
| India | Python | [Leetcode](https://t.co/u0OByxhcHA)
[Hackerrank](https://www.hackerrank.com/lokendra17) | -| [Yuri Spiridonov](https://github.com/YuriSpiridonov)
| Russia | Python | [Twitter](https://twitter.com/YuriSpiridonov)
[Leetcode](https://leetcode.com/yurispiridonov/)
[Hackerrank](https://www.hackerrank.com/YuriSpiridonov) | -| [Naveen Kashyap](https://github.com/naveenkash)
| India | Javascript | [Twitter](https://twitter.com/naveen_kashyapp)
[Leetcode](https://leetcode.com/naveenkash/) | -| [Rudra Mishra](https://github.com/Rudra407)
| India | C++ | [Twitter](https://twitter.com/ruDra_Mishra407)
[Leetcode](https://leetcode.com/rudramishra/) | -| [Sachin Singh Negi](https://github.com/sachinnegi)
| India | Python | [Twitter](https://twitter.com/SachinSinghNe17)
[Leetcode](https://leetcode.com/negisachin688/)
[Hackerrrak](https://www.hackerrank.com/negisachin688) | -| [Girish Thatte](https://github.com/girishgr8/)
| India | Java | [Leetcode](https://leetcode.com/girish13/)
[Hackerrank](https://www.hackerrank.com/procoder_13)
[Codechef](https://www.codechef.com/procoder_13) | -| [Kevin Chittilapilly](https://github.com/KevinChittilapilly)
| India | Java | [Leetcode](https://leetcode.com/being_kevin/)
[Hackerrank](https://www.hackerrank.com/ckevinvarghese11)
[Kaggle](https://www.kaggle.com/kevinchittilapilly) | -| [Nour Grati](https://github.com/Nour-Grati)
| Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/)
[Hackerrank](https://www.hackerrank.com/noor_grati)
[Twitter](https://twitter.com/GratiNour1) | -| [Avinash Trivedi](https://github.com/trivediavinash)
| India | C++ | [Leetcode](https://leetcode.com/avi_002/) | -| [Ishika Goel](https://github.com/ishikagoel5628)
| India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) | -| [Fenil Dobariya](https://github.com/ifenil)
| India | Java | [Github](https://github.com/ifenil) | -| [Prashansa Tanwar](https://github.com/prashansatanwar)
| India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) | -| [Ishu Raj](https://github.com/ir2010)
| India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) | -| [Rakesh Bhadhavath](https://github.com/Revenge-Rakesh)
| India | Java | [Leetcode](https://leetcode.com/goal_cracker/) | -| [Tarun Singh](https://github.com/TarunSingh56)
| India | C++ | [Leetcode](https://leetcode.com/_tarun/) | -| [Hardik Gupta](https://github.com/harrdy272)
| India | C++ | [codeforces](https://codeforces.com/profile/harrdy272)
[codechef](https://www.codechef.com/users/hardikg272)
[Hackerrank](https://www.hackerrank.com/hardikg272)
[LeetCode](https://leetcode.com/hardikg272/) | -| [Jaseem ck](https://github.com/Jaseemck)
| India | Python | [Github](https://github.com/Jaseemck) | -| [Ilias Khan](https://github.com/IliasKhan)
| India | C++ | [codechef](https://www.codechef.com/users/iliaskhan)
[Hackerrank](ckerrank.com/iliaskhan57)
[LeetCode](https://leetcode.com/ilias_khan/)
[codeforces](http://codeforces.com/profile/iliaskhan) | -| [Shamoyeeta Saha](https://github.com/Shamoyeeta)
| India | C++ | [Hackerrank](https://www.hackerrank.com/sahashamoyeeta)
[Github](https://github.com/Shamoyeeta) | -| [James Y](https://github.com/jameszu)
| New Zealand | python | [Github](https://github.com/jameszu) | -| [Hamza B](https://github.com/9Hamza)
| Saudi Arabia | Java | [Github](https://github.com/9Hamza) | -| [Meli Haktas](https://github.com/MercerFrey)
| Turkey | python | [Github](https://github.com/MercerFrey) | -| [Saurav Prateek](https://github.com/SauravP97)
| India | Java | [Github](https://github.com/SauravP97)
[Codechef](https://www.codechef.com/users/srvptk)
[Codeforces](https://codeforces.com/profile/srvptk97)
[Leetcode](https://leetcode.com/srvptk97) | -| [Anushka Verma](https://github.com/verma-anushka)
| India | C++ | [Portfolio](https://verma-anushka.github.io/anushkaverma/)
[LeetCode](https://leetcode.com/anushka_verma/) | -| [James H](https://github.com/HoangJames)
| United Kingdom | C++ | [Github](https://github.com/HoangJames) | -| [Franchis N. Saikia](https://github.com/Francode007)
| India | C++ | [Github](https://github.com/Francode007) | -| [Yarncha](https://github.com/yarncha)
| South Korea | C++ | [LeetCode](https://leetcode.com/yamcha/) | -| [Gamez0](https://github.com/Gamez0)
| South Korea | Python | [LeetCode](https://leetcode.com/Gamez0/) | -| [JeongDaHyeon](https://github.com/JeongDaHyeon)
| South Korea | Java | [GitHub](https://github.com/JeongDaHyeon) | -[Aysia](https://www.linkedin.com/in/aysiaelise/)
| USA | JavaScript | [GitHub](https://github.com/aysiae) -| [Poorvi Garg](https://github.com/POORVI111)
| India | C++ | [GitHub](https://github.com/POORVI111) -| [Lakshmanan Meiyappan](https://laxmena.com)
| India | C++ |[Website - Blog](https://laxmena.com)
[GitHub](https://github.com/laxmena)
[LinekdIn](https://www.linkedin.com/in/lakshmanan-meiyappan/) - - - - +| Name | Country | Programming Language | Where to find you
(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...) | +| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [Gourav R](https://github.com/GouravRusiya30/)
| India | Java | [codedecks](https://www.youtube.com/c/codedecks/)
[Hackerrank](https://www.hackerrank.com/gouravrusiya786)
[LeetCode](https://leetcode.com/rusiya/) | +| [Dima Vishnevetsky](https://github.com/dimshik100)
| Israel | JavaScript | [Twitter](https://twitter.com/dimshik100)
[Facebook](https://www.facebook.com/dimshik) | +| [Anuj Sharma](https://github.com/Optider/)
| India | Python | [Github](https://github.com/Optider) | +| [Lokendra Bohra](https://github.com/lokendra1704/)
| India | Python | [Leetcode](https://t.co/u0OByxhcHA)
[Hackerrank](https://www.hackerrank.com/lokendra17) | +| [Yuri Spiridonov](https://github.com/YuriSpiridonov)
| Russia | Python | [Twitter](https://twitter.com/YuriSpiridonov)
[Leetcode](https://leetcode.com/yurispiridonov/)
[Hackerrank](https://www.hackerrank.com/YuriSpiridonov) | +| [Naveen Kashyap](https://github.com/naveenkash)
| India | Javascript | [Twitter](https://twitter.com/naveen_kashyapp)
[Leetcode](https://leetcode.com/naveenkash/) | +| [Rudra Mishra](https://github.com/Rudra407)
| India | C++ | [Twitter](https://twitter.com/ruDra_Mishra407)
[Leetcode](https://leetcode.com/rudramishra/) | +| [Sachin Singh Negi](https://github.com/sachinnegi)
| India | Python | [Twitter](https://twitter.com/SachinSinghNe17)
[Leetcode](https://leetcode.com/negisachin688/)
[Hackerrrak](https://www.hackerrank.com/negisachin688) | +| [Girish Thatte](https://github.com/girishgr8/)
| India | Java | [Leetcode](https://leetcode.com/girish13/)
[Hackerrank](https://www.hackerrank.com/procoder_13)
[Codechef](https://www.codechef.com/procoder_13) | +| [Kevin Chittilapilly](https://github.com/KevinChittilapilly)
| India | Java | [Leetcode](https://leetcode.com/being_kevin/)
[Hackerrank](https://www.hackerrank.com/ckevinvarghese11)
[Kaggle](https://www.kaggle.com/kevinchittilapilly) | +| [Nour Grati](https://github.com/Nour-Grati)
| Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/)
[Hackerrank](https://www.hackerrank.com/noor_grati)
[Twitter](https://twitter.com/GratiNour1) | +| [Avinash Trivedi](https://github.com/trivediavinash)
| India | C++ | [Leetcode](https://leetcode.com/avi_002/) | +| [Ishika Goel](https://github.com/ishikagoel5628)
| India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) | +| [Fenil Dobariya](https://github.com/ifenil)
| India | Java | [Github](https://github.com/ifenil) | +| [Prashansa Tanwar](https://github.com/prashansatanwar)
| India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) | +| [Ishu Raj](https://github.com/ir2010)
| India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) | +| [Rakesh Bhadhavath](https://github.com/Revenge-Rakesh)
| India | Java | [Leetcode](https://leetcode.com/goal_cracker/) | +| [Tarun Singh](https://github.com/TarunSingh56)
| India | C++ | [Leetcode](https://leetcode.com/_tarun/) | +| [Hardik Gupta](https://github.com/harrdy272)
| India | C++ | [codeforces](https://codeforces.com/profile/harrdy272)
[codechef](https://www.codechef.com/users/hardikg272)
[Hackerrank](https://www.hackerrank.com/hardikg272)
[LeetCode](https://leetcode.com/hardikg272/) | +| [Jaseem ck](https://github.com/Jaseemck)
| India | Python | [Github](https://github.com/Jaseemck) | +| [Ilias Khan](https://github.com/IliasKhan)
| India | C++ | [codechef](https://www.codechef.com/users/iliaskhan)
[Hackerrank](ckerrank.com/iliaskhan57)
[LeetCode](https://leetcode.com/ilias_khan/)
[codeforces](http://codeforces.com/profile/iliaskhan) | +| [Shamoyeeta Saha](https://github.com/Shamoyeeta)
| India | C++ | [Hackerrank](https://www.hackerrank.com/sahashamoyeeta)
[Github](https://github.com/Shamoyeeta) | +| [James Y](https://github.com/jameszu)
| New Zealand | python | [Github](https://github.com/jameszu) | +| [Hamza B](https://github.com/9Hamza)
| Saudi Arabia | Java | [Github](https://github.com/9Hamza) | +| [Meli Haktas](https://github.com/MercerFrey)
| Turkey | python | [Github](https://github.com/MercerFrey) | +| [Saurav Prateek](https://github.com/SauravP97)
| India | Java | [Github](https://github.com/SauravP97)
[Codechef](https://www.codechef.com/users/srvptk)
[Codeforces](https://codeforces.com/profile/srvptk97)
[Leetcode](https://leetcode.com/srvptk97) | +| [Anushka Verma](https://github.com/verma-anushka)
| India | C++ | [Portfolio](https://verma-anushka.github.io/anushkaverma/)
[LeetCode](https://leetcode.com/anushka_verma/) | +| [James H](https://github.com/HoangJames)
| United Kingdom | C++ | [Github](https://github.com/HoangJames) | +| [Franchis N. Saikia](https://github.com/Francode007)
| India | C++ | [Github](https://github.com/Francode007) | +| [Yarncha](https://github.com/yarncha)
| South Korea | C++ | [LeetCode](https://leetcode.com/yamcha/) | +| [Gamez0](https://github.com/Gamez0)
| South Korea | Python | [LeetCode](https://leetcode.com/Gamez0/) | +| [JeongDaHyeon](https://github.com/JeongDaHyeon)
| South Korea | Java | [GitHub](https://github.com/JeongDaHyeon) | +| [Aysia](https://www.linkedin.com/in/aysiaelise/)
| USA | JavaScript | [GitHub](https://github.com/aysiae) | +| [Poorvi Garg](https://github.com/POORVI111)
| India | C++ | [GitHub](https://github.com/POORVI111) | +| [Lakshmanan Meiyappan](https://laxmena.com)
| India | C++ | [Website - Blog](https://laxmena.com)
[GitHub](https://github.com/laxmena)
[LinekdIn](https://www.linkedin.com/in/lakshmanan-meiyappan/) | +
⬆️ Back to Top From fd4c9aa3015058a3db2109dfdd3068e82119e301 Mon Sep 17 00:00:00 2001 From: Shambhavi Sharma <60618802+ShambhaviSharma0110@users.noreply.github.com> Date: Mon, 17 May 2021 14:29:41 +0530 Subject: [PATCH 121/157] added 189 (#165) * added 189 * added 189 * Update 189.Rotate array * added 189 * added 189 --- C++/189.Rotate-array.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 C++/189.Rotate-array.cpp 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] +*/ From d4a56b2f5241c3adbe8e390ee9547c9f8c5bb5be Mon Sep 17 00:00:00 2001 From: Jasbir Rajrana <68157847+jasbirrajrana@users.noreply.github.com> Date: Thu, 20 May 2021 14:28:11 +0530 Subject: [PATCH 122/157] fix: link to question findPeakElement.js (#168) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 58325e67..f076b8f5 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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](./javascript/findPeakElement.js) | o(Logn) | O(1) | Medium | 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 |
From 154068e2a58bd540fbd0fd101aba37f319c9319a Mon Sep 17 00:00:00 2001 From: Moulina Pradhan Date: Sat, 22 May 2021 11:18:00 +0530 Subject: [PATCH 123/157] Sum of two integer (#169) * Create Sum of Two Integers * Update Readme * Add time complexity and space complexity --- Java/Sum_of_two_integers.java | 15 +++++++++++++++ README.md | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Java/Sum_of_two_integers.java 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/README.md b/README.md index f076b8f5..44d611bf 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | ---- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | | 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java)
[Python](./Python/single-number.py)
[C++](./C++/Single-Number.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR | | 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./Python/single-number-ii.py)
[C++](./C++/Single-Number-II.cpp) | _O(n)_ | _O(1)_ | Medium | | | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py)
[C++](./C++/Single-Number-III.cpp) | _O(n)_ | _O(1)_ | Medium | | | +| 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) | _O(n)_ | _O(1)_ | Easy | | Using XOR | From 68163cc8e4d19dfb50b5375d8e589ad35c400c5f Mon Sep 17 00:00:00 2001 From: Moulina Pradhan Date: Sat, 29 May 2021 22:36:21 +0530 Subject: [PATCH 124/157] Evaluate reverse polish notation (#171) * Solution of Evaluate Reverse Polish Notation * Update evaluate_reverse_polish_notation.java * update readme.md --- Java/evaluate_reverse_polish_notation.java | 30 ++++++++++++++++++++++ README.md | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Java/evaluate_reverse_polish_notation.java diff --git a/Java/evaluate_reverse_polish_notation.java b/Java/evaluate_reverse_polish_notation.java new file mode 100644 index 00000000..feaae56a --- /dev/null +++ b/Java/evaluate_reverse_polish_notation.java @@ -0,0 +1,30 @@ + + +class Solution { + public int evalRPN(String[] tokens) { + Stack st = new Stack<>(); + int a,b; + for(String s: tokens){ + if(s.equals("+")){ + st.add(st.pop()+st.pop()); + } + else if(s.equals("*")){ + st.add(st.pop() * st.pop()); + } + else if(s.equals("/")){ + b=st.pop(); + a = st.pop(); + st.add(a/b); + } + else if(s.equals("-")){ + b = st.pop(); + a = st.pop(); + st.add(a-b); + } + else{ + st.add(Integer.parseInt(s)); + } + } + return st.pop(); + } +} diff --git a/README.md b/README.md index 44d611bf..3b2f26c5 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | ---- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ------ | ------ | ---------- | ---------------------- | ---- | | 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) | _O(n)_ | _O(n)_ | Easy | Stack | | | 084 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | [C++](./C++/Largest-Rectangle-in-Histogram.cpp) | _O(n)_ | _O(n)_ | Hard | Stack | -| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) | _O(n)_ | _O(1)_ | Medium | Stack | | +| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py)
[Java](./Java/evaluate_reverse_polish_notation.java) | _O(n)_ | _O(1)_ | Medium | Stack | | | 1047 | [Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) | [C++](./C++/remove-all-adjacent-duplicates-in-string.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | | | 682 | [Baseball Game](https://leetcode.com/problems/baseball-game/) | [C++](./C++/Baseball-Game.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | | | 1381 | [Design a Stack With Increment Operation](https://leetcode.com/problems/design-a-stack-with-increment-operation/) | [Java](./Java/Design-a-Stack-With-Increment-Operation.java) | _O(n)_ | _O(n)_ | Medium | Stack | | From e78db76e7f35d424e413802df1736575c572c06b Mon Sep 17 00:00:00 2001 From: KRISHANU SAINI <56930593+krishanu-2001@users.noreply.github.com> Date: Thu, 10 Jun 2021 22:32:45 +0530 Subject: [PATCH 125/157] Add 1486(C++) - Xor-operation-in-an-array (#172) * Add xor-operation-in-an-array c++ * Add readme * Fix readme * Fix xor-operation-in-an-array --- C++/xor-operation-in-an-array.cpp | 12 ++++++++++++ README.md | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 C++/xor-operation-in-an-array.cpp 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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) | _O(n)_ | _O(1)_ | Easy | | Using XOR | +| 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 |
From 7d9d0a50e5d7226c5461d409082494284eb143f8 Mon Sep 17 00:00:00 2001 From: Sachin Date: Fri, 2 Jul 2021 23:47:32 +0530 Subject: [PATCH 126/157] Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function) (#178) * String to Integer converter like ATOI in C/C++ Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function) * Rename Java file as per standard and add details to .md file Rename Java file as per standard and add details to .md file --- Java/string-to-integer-atoi.java | 65 ++++++++++++++++++++++++++++++++ README.md | 4 +- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 Java/string-to-integer-atoi.java 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/README.md b/README.md index 0e229327..a774967b 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | | | 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | | | 767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./Python/reorganize-string.py) | _O(n)_ | _O(n)_ | Medium | | | - +| 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 | | |
⬆️ Back to Top @@ -490,7 +490,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) |
⬆️ Back to Top From 6f4b6399e044683f28c41bfd9f77740717de2341 Mon Sep 17 00:00:00 2001 From: Priyanka Suthaar <79053662+Priyanka94suthaar@users.noreply.github.com> Date: Fri, 2 Jul 2021 23:52:06 +0530 Subject: [PATCH 127/157] Adding solution for Day 22 Challenge Problem (#176) Co-authored-by: Priyanka Suthaar --- .../Day22StrSubsequenceCount.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Java/June-LeetCoding-Challenge/Day22StrSubsequenceCount.java 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; + } + +} From c79cdff93ed589506c903f261ddcf009549b048b Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 3 Jul 2021 19:30:29 +0530 Subject: [PATCH 128/157] updated --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a774967b..b550bb5c 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,18 @@

- - - - + + - +

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) From d99ff4ffbec89b4d2d3bd20bbc964e2959e47fe2 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 3 Jul 2021 19:32:51 +0530 Subject: [PATCH 129/157] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index b550bb5c..f429ab49 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,15 @@

- + -

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) From c3f620508c313056bd51a76f29e9e0083d36fd49 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 3 Jul 2021 19:35:36 +0530 Subject: [PATCH 130/157] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f429ab49..cd8cdf35 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ Issues Badge --> -### Got stuck in a LeetCode question? This repository will help you by providing approach of solving the problems from LeetCode platform. +### Got stuck in a LeetCode question? +### This repository will help you by providing approach of solving the problems from LeetCode platform. ### [Contributors](#contributors) helped us in providing these Awesome solutions. From f08647ec8b2b96ab65d83c860a2b3681172caa8e Mon Sep 17 00:00:00 2001 From: Priyanka Suthaar <79053662+Priyanka94suthaar@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:22:48 +0530 Subject: [PATCH 131/157] String Operations Count Program (#179) Co-authored-by: Hemant Suthar --- .../StringOperationsCount.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Java/June-LeetCoding-Challenge/StringOperationsCount.java 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; + } +} From 064cc1c273a6596e08d8fc30eb8cc01d396dacc7 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 21 Jul 2021 15:53:56 +0530 Subject: [PATCH 132/157] telegram link added --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd8cdf35..be1d5d63 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ # [LeetCode-Solutions](https://www.youtube.com/playlist?list=PLlUdLC2oSxz2Y1g6V8oRCzauOvbnKl2Ee)

- +

Join Us on Telegram & Facebook

+ + + + From 5c2c33060e1c91da2b19177f3558dd8fbbbe7bd7 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Wed, 21 Jul 2021 15:55:24 +0530 Subject: [PATCH 133/157] updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be1d5d63..83a7f36a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Forks Badge GitHub contributors -[![GitHub issues by-label](https://img.shields.io/github/issues-pr-closed-raw/codedecks-in/LeetCode-Solutions.svg)](https://github.com/codedecks-in/LeetCode-Solutions/pulls?q=is%3Apr+is%3Aclosed) + From c1b60a64ffafe02e215bbfecd917862b7c80329b Mon Sep 17 00:00:00 2001 From: Amisha Sahu <58816552+Amisha328@users.noreply.github.com> Date: Thu, 29 Jul 2021 17:50:59 +0530 Subject: [PATCH 134/157] 100. Same Tree BFS Problem in C++ (#181) * BFS LeetCode problem 100 in C++ * Delete 100_Same_Tree.cpp * BFS LeetCode problem 100 in C++ --- C++/100_Same_Tree.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 C++/100_Same_Tree.cpp 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 From 7da3fcb5f40f35f88efdb22e241f1064bef98adc Mon Sep 17 00:00:00 2001 From: Amisha Sahu <58816552+Amisha328@users.noreply.github.com> Date: Sat, 31 Jul 2021 09:03:46 +0530 Subject: [PATCH 135/157] Updated README.md with question link and contribution (#182) * BFS LeetCode problem 100 in C++ * Delete 100_Same_Tree.cpp * BFS LeetCode problem 100 in C++ * Added problem link & my profile in contribution Updated README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 83a7f36a..b13f42ee 100644 --- a/README.md +++ b/README.md @@ -326,7 +326,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 @@ -493,6 +495,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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)
⬆️ Back to Top From cc228765d76b722a1c3b96772023546e4e010578 Mon Sep 17 00:00:00 2001 From: Yashaswini <57534356+Yashaswinihoney@users.noreply.github.com> Date: Sun, 1 Aug 2021 16:57:49 +0530 Subject: [PATCH 136/157] added 143.Reorder_List.cpp using cpp , 95.98% faster (#183) * Create 143.Reorder_List.cpp * readme --- C++/143.Reorder_List.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ README.md | 4 +++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 C++/143.Reorder_List.cpp 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/README.md b/README.md index b13f42ee..c93108c0 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +| 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 | + |
From c046825379826181a8fd857757e8ebf4914d203a Mon Sep 17 00:00:00 2001 From: Harshit Gupta Date: Mon, 2 Aug 2021 16:06:34 +0530 Subject: [PATCH 137/157] Add solution for 3rd LeetCode Practice Problem - Longest Substring Without Repeating Characters (#184) * Add solution for 3rd LeetCode Practice Problem - Longest Substring Without Repeating Characters This commit adds a well-commented and human-readable Python 3 program to solve the third LeetCode Practice Problem viz., "Longest Substring Without Repeating Characters". The code is judged as Accepted on LeetCode, on 1st August 2021 (the same day this PR is initiated). * Update README.md Sorted Strings Table Entries in ascending order as per the # Problem ID column, and added entry for Python solution to newly added solution to Strings #3: Longest Substring Without Repeating Characters * Rename 3. Longest Substring Without Repeating Characters.py to Longest_Substring_Without_Repeating_Characters.py Renamed this file to Longest_Substring_Without_Repeating_Characters.py in order to match file naming conventions of the repository, as mentioned in PULL_REQUEST_TEMPLATE * Fix Longest_Substring_Without_Repeating_Characters solution link Fixed the solution link for Longest_Substring_Without_Repeating_Characters.py file in README file --- ..._Substring_Without_Repeating_Characters.py | 29 +++++++++++++++++++ README.md | 15 +++++----- 2 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 Python/Longest_Substring_Without_Repeating_Characters.py 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/README.md b/README.md index c93108c0..731afe53 100644 --- a/README.md +++ b/README.md @@ -156,18 +156,19 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu # String | # | Title | Solution | Time | Space | Difficulty | Tag | Note | -| ---- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------------- | +| :--: | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------------- | +| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [Python](./Python/Longest_Substring_Without_Repeating_Characters.py) | _O(n)_ | _O(n)_ | Medium | `Hash Table`
`Sliding Window` | Open for improvisation, mentioned time and space complexities unconfirmed | +| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/) | [Java](./Java/string-to-integer-atoi.java) | _O(n)_ | _O(1)_ | Medium | | | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | | +| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/) | [Java](./Java/reverse-words-in-a-string.java) | _O(1)_ | _O(n)_ | Medium | | | | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note/) | [Java](./Java/ransom-note.java) | _O(1)_ | _O(n)_ | Easy | | Character Count | | 387 | [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/) | [Java](./Java/first-unique-character-in-a-string.java) | _O(n)_ | _O(1)_ | Easy | | Character Count | -| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/) | [Java](./Java/reverse-words-in-a-string.java) | _O(1)_ | _O(n)_ | Medium | | | | 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Java](./Java/detect-capital-use.java) | _O(n)_ | _O(1)_ | Easy | | | +| 767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./Python/reorganize-string.py) | _O(n)_ | _O(n)_ | Medium | | | +| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | | | 1221 | [Split a String in Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings/) | [Python](./Python/split-a-string-in-balanced-strings.py) | _O(n)_ | _O(1)_ | Easy | | | -| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Java](./Java/max-nesting-depth-parentheses.java) | _O(n)_ | _O(1)_ | Easy | | | | 1374 | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | [Java](./Java/generate-a-string-with-characters-that-have-odd-counts.java) | _O(n)_ | _O(1)_ | Easy | | | -| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings/) | [Java](./Java/buddy-strings.java) | _O(n)_ | _O(1)_ | Easy | | | -| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Java](./Java/palindrome-number.java) | _O(n)_ | _O(1)_ | Easy | | | -| 767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./Python/reorganize-string.py) | _O(n)_ | _O(n)_ | Medium | | | -| 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 | | | +| 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 From 56c1fa285f1efdf80dcddbb2225ec05a932f32e3 Mon Sep 17 00:00:00 2001 From: Y Patterns <85457983+YaadR@users.noreply.github.com> Date: Fri, 6 Aug 2021 13:33:40 +0300 Subject: [PATCH 138/157] Added 13.Roman_to_Integer.cpp (#185) * added 13.Roman_to_Integer.cpp * Update Math table on README Added c++ linked selution to Roman_to_Integer * Added 20. Valid_Parentheses.cpp * Added The README missing part * Changed file name from 20. Valid_Parentheses to Valid_Parentheses * Fixed link Indeed I've forgotten to adjust the path as well. Thanks for the patience --- C++/Roman_to_Integer.cpp | 60 +++++++++++++++++++++++++++++++++++++++ C++/Valid_Parentheses.cpp | 58 +++++++++++++++++++++++++++++++++++++ README.md | 4 +-- 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 C++/Roman_to_Integer.cpp create mode 100644 C++/Valid_Parentheses.cpp diff --git a/C++/Roman_to_Integer.cpp b/C++/Roman_to_Integer.cpp new file mode 100644 index 00000000..a54fc83f --- /dev/null +++ b/C++/Roman_to_Integer.cpp @@ -0,0 +1,60 @@ +#include + +/*** 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++/Valid_Parentheses.cpp b/C++/Valid_Parentheses.cpp new file mode 100644 index 00000000..0534dba2 --- /dev/null +++ b/C++/Valid_Parentheses.cpp @@ -0,0 +1,58 @@ +#include +#include +/* +Example 1: +Input: s = "()" +Output: true + +Example 2: +Input: s = "()[]{}" +Output: true + +Example 3: +Input: s = "(]" +Output: false + +Example 4: +Input: s = "([)]" +Output: false + +Example 5: +Input: s = "{[]}" +Output: true +*/ + +class Solution { +public: + bool isValid(string s) { + list open; + if(s.length()%2!=0) + return false; + for(int i=0; i [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Note | | ---- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ------ | ------ | ---------- | ---------------------- | ---- | -| 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) | _O(n)_ | _O(n)_ | Easy | Stack | | +| 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) [C++](./C++/Vlalid_Parentheses.cpp) | _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 | | @@ -309,7 +309,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | | | 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [Java](./Java/integer-to-roman.java) | _O(n)_ | _O(1)_ | Medium | Math | | -| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Java](./Java/roman-to-integer.java) | _O(n)_ | _O(1)_ | Easy | Math | | +| 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 | | From 047d85b01ff02885cbcf91d0575ff9c0875e6b03 Mon Sep 17 00:00:00 2001 From: Shrimadh <64469917+Shrimadh@users.noreply.github.com> Date: Sun, 22 Aug 2021 20:11:23 +0530 Subject: [PATCH 139/157] Number of Islands question in C++ language. Pull Request for Issue #77 (#188) * added number of islands question * Update number-of-islands.cpp * Update README.md * Update README.md * Update README.md --- C++/number-of-islands.cpp | 49 +++++++++++++++++++++++++++++++++++++++ README.md | 5 ++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 C++/number-of-islands.cpp 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | -|
- +
@@ -500,6 +500,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) From 44419fabb65193698000d53308400047722341d7 Mon Sep 17 00:00:00 2001 From: Gantavya Malviya <39916680+gantavyamalviya@users.noreply.github.com> Date: Fri, 1 Oct 2021 15:41:51 +0530 Subject: [PATCH 140/157] added leetcode 566 (#193) --- C++/Reshape-the-Matrix.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 C++/Reshape-the-Matrix.cpp 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 Date: Fri, 1 Oct 2021 15:42:37 +0530 Subject: [PATCH 141/157] Added Redundant connections problem from Leetcode-684 (#192) Added Problem Link at start --- C++/RedundantConnection.cpp | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 C++/RedundantConnection.cpp 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; + } +}; From 76df15bcb615af268072b8f44a827f24e4051125 Mon Sep 17 00:00:00 2001 From: Saiteja Mahankali <81941814+saiteja-2731@users.noreply.github.com> Date: Fri, 1 Oct 2021 18:36:46 +0530 Subject: [PATCH 142/157] Issue #194--Added Daily Temperatures problem (#197) * Added Daily Temperatures problem * Update Daily_Temperatures.cpp --- C++/Daily_Temperatures.cpp | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 C++/Daily_Temperatures.cpp 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; + } +}; From 77b4fdca0f6f32c0c0e3fd3b810fbb0616436bf0 Mon Sep 17 00:00:00 2001 From: pratik1424 <63138918+pratik1424@users.noreply.github.com> Date: Fri, 1 Oct 2021 20:33:41 +0530 Subject: [PATCH 143/157] Issue #194--Added : 102. Binary Tree Level Order Traversal (#198) * Added : 102. Binary Tree Level Order Traversal * Update README.md --- C++/Binary-Tree-Level-Order-Traversal.cpp | 61 +++++++++++++++++++++++ README.md | 1 + 2 files changed, 62 insertions(+) create mode 100644 C++/Binary-Tree-Level-Order-Traversal.cpp 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/README.md b/README.md index e0486c1a..bcd3ee1a 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
From 6939e9e8444323e9c2a98168a3711634fa751b6e Mon Sep 17 00:00:00 2001 From: Lokesh Raj Singhi Date: Fri, 1 Oct 2021 22:06:38 +0545 Subject: [PATCH 144/157] Updated Readme for Swap Nodes in Pairs (#201) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index bcd3ee1a..322a8143 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,9 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +
From b24e68d6a86b81d58927aa934d6c2199dffa370a Mon Sep 17 00:00:00 2001 From: pranav-git-hub <66816957+pranav-git-hub@users.noreply.github.com> Date: Fri, 1 Oct 2021 21:52:36 +0530 Subject: [PATCH 145/157] 20. Valid Parentheses (#196) * Create 20.ValidParentheses.py * Create 20.ValidParentheses.java * Delete 20.ValidParentheses.py * Update 20.ValidParentheses.java * Update README.md --- Java/20.ValidParentheses.java | 16 ++++++++++++++++ README.md | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Java/20.ValidParentheses.java diff --git a/Java/20.ValidParentheses.java b/Java/20.ValidParentheses.java new file mode 100644 index 00000000..6240d491 --- /dev/null +++ b/Java/20.ValidParentheses.java @@ -0,0 +1,16 @@ +//Time Complexity n +//Space Complexity n +public boolean isValid(String s) { + Stack 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/README.md b/README.md index 322a8143..e9e43bfc 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Note | | ---- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ------ | ------ | ---------- | ---------------------- | ---- | -| 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) [C++](./C++/Vlalid_Parentheses.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | | +| 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) [C++](./C++/Vlalid_Parentheses.cpp)[Java](./Java/20.ValidParentheses.java) | _O(n)_ | _O(n)_ | Easy | Stack | | | 084 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | [C++](./C++/Largest-Rectangle-in-Histogram.cpp) | _O(n)_ | _O(n)_ | Hard | Stack | | 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py)
[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 | | From e37f97e8225899d6ec69576634bd7d787fe470b7 Mon Sep 17 00:00:00 2001 From: Lokesh Raj Singhi Date: Fri, 1 Oct 2021 22:26:28 +0545 Subject: [PATCH 146/157] Create Swap-nodes-in-pairs.cpp (#200) * Create Swap-nodes-in-pairs.cpp * Update Swap-nodes-in-pairs.cpp --- C++/Swap-nodes-in-pairs.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 C++/Swap-nodes-in-pairs.cpp 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) From da168da9a54a8f12fd6fc3614dbc730c4319cf6a Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Fri, 1 Oct 2021 22:15:24 +0530 Subject: [PATCH 147/157] reformatted --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index e9e43bfc..e6e5d46e 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,6 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | - |
@@ -500,9 +499,8 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) | +| [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)
⬆️ Back to Top From 12881a258eb41db97d2746f28485fb0bc66fcb68 Mon Sep 17 00:00:00 2001 From: Surbhi Mayank <58289829+surbhi2408@users.noreply.github.com> Date: Sun, 3 Oct 2021 16:02:13 +0545 Subject: [PATCH 148/157] 17. Letter Combinations of a Phone Number in C++ (#216) * Letter Combinations of a Phone Number added * Update README.md * Update README.md --- C++/letter-combinations-of-a-phone-number.cpp | 40 +++++++++++++++++++ README.md | 2 + 2 files changed, 42 insertions(+) create mode 100644 C++/letter-combinations-of-a-phone-number.cpp diff --git a/C++/letter-combinations-of-a-phone-number.cpp b/C++/letter-combinations-of-a-phone-number.cpp new file mode 100644 index 00000000..792a3476 --- /dev/null +++ b/C++/letter-combinations-of-a-phone-number.cpp @@ -0,0 +1,40 @@ +class Solution { +public: + unordered_map intToCharsMap; + + void backtracking(string::iterator lf,string::iterator rt,string &path,vector &result) + { + if(lf == rt) + { + result.push_back(path); + return; + } + for(auto c : intToCharsMap[*lf]) + { + path.push_back(c); + backtracking(next(lf,1),rt,path,result); + path.pop_back(); // if a character doesnot matches then we pop that character from the string and again backtrack. + } + } + vector letterCombinations(string digits) + { + int n = digits.size(); + if(digits == "") + return {}; + string path; + // result array stores every string that represents that digit. + vector result; + intToCharsMap = { + {'2', "abc"}, + {'3', "def"}, + {'4', "ghi"}, + {'5', "jkl"}, + {'6', "mno"}, + {'7', "pqrs"}, + {'8', "tuv"}, + {'9', "wxyz"}, + }; + backtracking(digits.begin(),digits.end(),path,result); + return result; + } +}; diff --git a/README.md b/README.md index e6e5d46e..36d17c18 100644 --- a/README.md +++ b/README.md @@ -364,6 +364,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 037 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver/) | [C++](./C++/Sudoku-Solver.cpp) | _O(n^2)_ | _O(1)_ | Hard | Hash Table | | | 980 | [Unique Paths III](https://leetcode.com/problems/unique-paths-iii/) | [C++](./C++/Unique-Paths-III.cpp) | _O(R * C * 2 ^ (R \* C))_ | _O(R \* C)_ | Hard | DFS, Memoization | | | 39 | [Combination Sum](https://leetcode.com/problems/combination-sum/) | [C++](./C++/combination-sum.cpp) | _O(2^n)_ | _O(n)_ | Medium | Array, Backtracking | | +| 17 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/) | [C++](./C++/letter-combinations-of-a-phone-number.cpp) | _O(4^n)_ | _O(n)_ | Medium | String, Hash Table, Backtracking | |
@@ -502,6 +503,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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) +| [Surbhi Mayank](https://github.com/surbhi2408)
| India | C++ | [GitHub](https://github.com/surbhi2408) From 87caedc9dcd521bdf4fa338fd469799194fd4571 Mon Sep 17 00:00:00 2001 From: Manish kasera <66238224+Manish-kasera@users.noreply.github.com> Date: Tue, 5 Oct 2021 00:12:15 +0530 Subject: [PATCH 149/157] Added FizzBuzz,WaterBottle,SignOf and BrokenCal Solution In Java (#203) * Added FizzBuzz,WaterBottle,SignOf and BrokenCal Solution * Removed main function and unnecessary code * Updated README.md Co-authored-by: Manish --- Java/BrokenCalculator.java | 16 ++++++++++++++++ Java/FizzBuzz.java | 23 +++++++++++++++++++++++ Java/SignOf.java | 18 ++++++++++++++++++ Java/WaterBottles.java | 17 +++++++++++++++++ README.md | 4 ++++ 5 files changed, 78 insertions(+) create mode 100644 Java/BrokenCalculator.java create mode 100644 Java/FizzBuzz.java create mode 100644 Java/SignOf.java create mode 100644 Java/WaterBottles.java diff --git a/Java/BrokenCalculator.java b/Java/BrokenCalculator.java new file mode 100644 index 00000000..4a119a05 --- /dev/null +++ b/Java/BrokenCalculator.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/broken-calculator/ + + public int brokenCalc(int startValue, int target) { + + + if(startValue >= target){ + return startValue - target; + } + + if(target % 2 == 0){ + return 1+brokenCalc(startValue,target/2); + } + + return 1+brokenCalc(startValue,target+1); + + } diff --git a/Java/FizzBuzz.java b/Java/FizzBuzz.java new file mode 100644 index 00000000..9034c2c0 --- /dev/null +++ b/Java/FizzBuzz.java @@ -0,0 +1,23 @@ + +import java.util.ArrayList; +import java.util.List; + +// https://leetcode.com/problems/fizz-buzz/ + + + public List fizzBuzz(int n) { + List s = new ArrayList<>(); + + for (int i = 1; i <= n ; i++) { + if( i % 15 == 0){ + s.add("FizzBuzz"); + }else if( i % 3 == 0){ + s.add("Fizz"); + }else if(i % 5 == 0){ + s.add("Buzz"); + }else{ + s.add(Integer.toString(i)); + } + } + return s; + } diff --git a/Java/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/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/README.md b/README.md index 36d17c18..1c1babf6 100644 --- a/README.md +++ b/README.md @@ -314,6 +314,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
From e76c11594a5a5a7ae4491353ff069b19190bd142 Mon Sep 17 00:00:00 2001 From: Fernanda Dagostin <33377159+fernandadagostin@users.noreply.github.com> Date: Mon, 4 Oct 2021 14:44:07 -0400 Subject: [PATCH 150/157] Single number js (#225) * Single Number JavaScript * single number JavaScript added tests --- JavaScript/single-number.js | 52 +++++++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 JavaScript/single-number.js 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/README.md b/README.md index 1c1babf6..eb378ded 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial | | ---- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------------------------------- | -| 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java)
[Python](./Python/single-number.py)
[C++](./C++/Single-Number.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR | +| 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 | From 2c475f05552668587456d9c944cf14519fc20968 Mon Sep 17 00:00:00 2001 From: Nikhil Shanbhag <61755381+Nikhil-1503@users.noreply.github.com> Date: Tue, 5 Oct 2021 00:16:18 +0530 Subject: [PATCH 151/157] Added solution for Spiral-matrix in cpp (#205) * Create Spiral-matrix.cpp * Update README.md --- C++/Spiral-matrix.cpp | 37 +++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 39 insertions(+) create mode 100644 C++/Spiral-matrix.cpp 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/README.md b/README.md index eb378ded..f3a90178 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | +
From 190cc17483a0331aebeaccfb5b50675320c158a1 Mon Sep 17 00:00:00 2001 From: Akshay Chopade Date: Tue, 5 Oct 2021 00:18:34 +0530 Subject: [PATCH 152/157] Added 118. Pascal's Triangle solution in java (#206) * Added 118. Pascal's Triangle solution in java * Delete .gitignore * Delete misc.xml * Delete modules.xml * Delete vcs.xml * Update README.md * Delete LeetCode-Solutions.iml --- Java/PascalsTriangle118.java | 29 +++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 30 insertions(+) create mode 100644 Java/PascalsTriangle118.java 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | # | Title | Solution | Time | Space | Difficulty | Note | Video Explaination | | ------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------ | ------------- | ---------- | ------------------ | ---------------------------------------- | +| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/) | [Java](./Java/PascalsTriangle118.java) | _O(N^2)_ | _O(N)_ | Easy | | | | 56 | [Merge Intervals](https://leetcode.com/problems/merge-intervals) | [Python](./Python/56_MergeIntervals.py) | _O(nlogn)_ | _O(n)_ | Medium | Intervals | | | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [Java](./Java/missing-number.java) | _O(n)_ | _O(1)_ | Easy | Array | [Tutorial](https://youtu.be/VwvGEE_OGss) | | 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | [Java](./Java/Degree-of-an-Array.java) | _O(n)_ | _O(n)_ | Easy | Array | | From 34821d15a66a5da9e453896b284d811d89524092 Mon Sep 17 00:00:00 2001 From: Shreyas Shrawage <55741087+shreyventure@users.noreply.github.com> Date: Tue, 5 Oct 2021 00:23:58 +0530 Subject: [PATCH 153/157] Added solution for Jump game (55) using Dynamic Programming (#217) * Added solution for Jump game (55) using Dynamic Programming * Edited README.md --- Python/jumpGame.py | 34 ++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 Python/jumpGame.py diff --git a/Python/jumpGame.py b/Python/jumpGame.py new file mode 100644 index 00000000..a522c3cd --- /dev/null +++ b/Python/jumpGame.py @@ -0,0 +1,34 @@ +# You are given an integer array nums. You are initially positioned at the array's first index, +# and each element in the array represents your maximum jump length at that position. +# Return true if you can reach the last index, or false otherwise. + +# Input: nums = [2,3,1,1,4] +# Output: true +# Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index. + +# Input: nums = [3,2,1,0,4] +# Output: false +# Explanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index. + +''' + Time Complexity: O(n), + Space Complexity: O(n) +''' + +def canJump(nums): + ptr1 = len(nums) - 1 + ptr2 = ptr1 - 1 + + while ptr2 >= 0: + if nums[ptr2] >= ptr1 - ptr2: + ptr1 = ptr2 + ptr2 -= 1 + else : + ptr2 -= 1 + + if ptr1 == 0: + return True + else: + return False + +print(canJump[3,2,1,0,4]) \ No newline at end of file diff --git a/README.md b/README.md index bd6f50aa..d9619791 100644 --- a/README.md +++ b/README.md @@ -394,6 +394,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 174 | [Dungeon Game](https://leetcode.com/problems/dungeon-game/) | [C++](./C++/dungeon-game.pp) | _O(M\*N)_ | _O(M\*N)_ | Hard | Dynamic Programming | | | 070 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | [Java](./Java/climbing-stairs.java) | _O(N)_ | _O(1)_ | Easy | DP | | | 730 | [Count Different Palindromic Subsequences](https://leetcode.com/problems/count-different-palindromic-subsequences/) | [C++](./C++/Count-Different-Palindromic-Subsequences.cpp) | _O(N\*N)_ | _O(N\*N)_ | Hard | DP | | +| 55 | [Jump Game](https://leetcode.com/problems/jump-game/) | [Python](./Python/jumpGame.py) | _O(N)_ | _O(N)_ | Medium | DP | |
@@ -510,6 +511,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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)
⬆️ Back to Top From 3811d19fa6f82b0f680b8f4c7f535641bc72439d Mon Sep 17 00:00:00 2001 From: Nishit Jain Date: Fri, 8 Oct 2021 21:17:08 +0530 Subject: [PATCH 154/157] Basek python (#235) * added Leetcode #1837 * repaired indent error * Update README.md --- Python/baseK.py | 17 +++++++++++++++++ README.md | 1 + 2 files changed, 18 insertions(+) create mode 100644 Python/baseK.py 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/README.md b/README.md index d9619791..41adf573 100644 --- a/README.md +++ b/README.md @@ -321,6 +321,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | |
From 42b5e1748f271ab3ea5113fdc2cf19f0b47a866e Mon Sep 17 00:00:00 2001 From: ShriAgashe <57454143+ShriAgashe@users.noreply.github.com> Date: Fri, 8 Oct 2021 21:22:02 +0530 Subject: [PATCH 155/157] 238. Product of Array Except Self (#228) * Solution to problem 238 * Updated Readme Added the row of my problem --- C++/238.Product_of_array_except_self | 54 ++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 55 insertions(+) create mode 100644 C++/238.Product_of_array_except_self 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 [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 |
From 80c004eafd2a4c937f59f7a909edb70efc672ea7 Mon Sep 17 00:00:00 2001 From: Gourav Rusiya Date: Sat, 22 Apr 2023 17:49:04 +0530 Subject: [PATCH 156/157] Update README.md (#366) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1dcb41a5..b2cac739 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

Join Us on Telegram & Facebook

- + From 214fdad3962a4d895deb93a06c1bd425c22d682b Mon Sep 17 00:00:00 2001 From: Amrit <0902cs221009@rjit.ac.in> Date: Tue, 18 Mar 2025 18:49:42 +0530 Subject: [PATCH 157/157] added problem number 011 (container-with-most-water)(https://leetcode.com/problems/container-with-most-water/) (#501) * added problem container-with-most-water and updated readme --- C++/container-with-most-water.cpp | 32 +++++++++++++++++++++++++++++++ README.md | 5 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 C++/container-with-most-water.cpp 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/README.md b/README.md index b2cac739..85accc7c 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [Python](./Python/pascals-triangle-ii.py) | _O(N^2)_ | _O(K)_ | Easy | | | | 1480 | [Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/) | [Java](./Java/running-sum-of-1d-array.java) | _O(N)_ | _O(N)_ | Easy | Simple sum | | | 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/) | [Python](./Python/trapping_rain.py) | _O(N^2)_ | _O(N)_ | Hard | Array | | -| 11 | [Container with Most Water](https://leetcode.com/problems/container-with-most-water/) | [Python](./Python/container_with_most_water.py) | _O(N)_ | _O(N)_ | Medium | Array Two Pointers | | +| 11 | [Container with Most Water](https://leetcode.com/problems/container-with-most-water/) | [Python](./Python/container_with_most_water.py)
[C++](./C++/container-with-most-water.cpp) | _O(N)_ | _O(N)_ | Medium | Array Two Pointers | | | 1134 🔒 | [Armstrong Number](https://leetcode.com/problems/armstrong-number/) | [Java](./Java/Armstrong-Number.java) | _O(N)_ | _O(1)_ | Easy | | | | 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets/) | [Python](./Python/count-good-triplets.py) | _O(N^3)_ | _O(1)_ | Easy | | | | 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/) | [Java](./Java/matrix-diagonal-sum.java) | _O(N)_ | _O(1)_ | Easy | | | @@ -297,6 +297,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 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 | | +
⬆️ Back to Top @@ -515,6 +516,8 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [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/) +