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 01/40] 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 02/40] 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 03/40] 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 04/40] 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 05/40] 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 06/40] 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 07/40] 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 08/40] 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 09/40] 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 10/40] 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 11/40] 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 12/40] 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 13/40] 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 14/40] 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 15/40] 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 16/40] 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 17/40] 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 18/40] 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 19/40] 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 20/40] 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 21/40] 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 22/40] 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 23/40] 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 24/40] 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 25/40] 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 26/40] 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 27/40] 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 28/40] 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 29/40] 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 30/40] 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 31/40] 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 32/40] 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 33/40] 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 34/40] 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 35/40] 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 36/40] 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 37/40] 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 38/40] 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 39/40] 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 40/40] 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/) +