From cfde8cc60ceae6a3775ada12d95011ccf11d8270 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Thu, 28 Dec 2023 13:36:31 +0200 Subject: [PATCH] Added tasks 1-46 --- .../G0001_0100/S0001_two_sum/readme.md | 59 + .../S0002_add_two_numbers/readme.md | 66 + .../readme.md | 75 + .../readme.md | 90 ++ .../readme.md | 72 + .../S0006_zigzag_conversion/readme.md | 79 + .../S0007_reverse_integer/readme.md | 56 + .../S0008_string_to_integer_atoi/readme.md | 160 ++ .../S0009_palindrome_number/readme.md | 64 + .../readme.md | 90 ++ .../S0011_container_with_most_water/readme.md | 68 + LeetCodeNet/G0001_0100/S0015_3sum/readme.md | 80 + .../readme.md | 71 + .../readme.md | 66 + .../S0020_valid_parentheses/readme.md | 76 + .../S0021_merge_two_sorted_lists/readme.md | 68 + .../S0022_generate_parentheses/readme.md | 57 + .../S0023_merge_k_sorted_lists/readme.md | 102 ++ .../S0024_swap_nodes_in_pairs/readme.md | 78 + .../S0025_reverse_nodes_in_k_group/readme.md | 92 ++ .../S0031_next_permutation/readme.md | 77 + .../S0032_longest_valid_parentheses/readme.md | 82 ++ .../readme.md | 77 + .../readme.md | 68 + .../S0035_search_insert_position/readme.md | 69 + .../S0039_combination_sum/readme.md | 87 ++ .../S0041_first_missing_positive/readme.md | 63 + .../S0042_trapping_rain_water/readme.md | 67 + .../G0001_0100/S0045_jump_game_ii/readme.md | 58 + .../G0001_0100/S0046_permutations/readme.md | 67 + README.md | 1288 ++++++++++++++++- 31 files changed, 3570 insertions(+), 2 deletions(-) create mode 100644 LeetCodeNet/G0001_0100/S0001_two_sum/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0002_add_two_numbers/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0006_zigzag_conversion/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0007_reverse_integer/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0009_palindrome_number/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0010_regular_expression_matching/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0011_container_with_most_water/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0015_3sum/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0020_valid_parentheses/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0022_generate_parentheses/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0031_next_permutation/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0035_search_insert_position/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0039_combination_sum/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0041_first_missing_positive/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0042_trapping_rain_water/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0045_jump_game_ii/readme.md create mode 100644 LeetCodeNet/G0001_0100/S0046_permutations/readme.md diff --git a/LeetCodeNet/G0001_0100/S0001_two_sum/readme.md b/LeetCodeNet/G0001_0100/S0001_two_sum/readme.md new file mode 100644 index 0000000..1413b91 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0001_two_sum/readme.md @@ -0,0 +1,59 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 1\. Two Sum + +Easy + +Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. + +You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. + +You can return the answer in any order. + +**Example 1:** + +**Input:** nums = [2,7,11,15], target = 9 + +**Output:** [0,1] + +**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1]. + +**Example 2:** + +**Input:** nums = [3,2,4], target = 6 + +**Output:** [1,2] + +**Example 3:** + +**Input:** nums = [3,3], target = 6 + +**Output:** [0,1] + +**Constraints:** + +* 2 <= nums.length <= 104 +* -109 <= nums[i] <= 109 +* -109 <= target <= 109 +* **Only one valid answer exists.** + +**Follow-up:** Can you come up with an algorithm that is less than O(n2) time complexity? + +## Solution + +```csharp +public class Solution { + public int[] TwoSum(int[] numbers, int target) { + Dictionary indexMap = new Dictionary(); + for (int i = 0; i < numbers.Length; i++) { + int requiredNum = target - numbers[i]; + if (indexMap.ContainsKey(requiredNum)) { + return new int[] {indexMap[requiredNum], i}; + } + indexMap[numbers[i]] = i; + } + return new int[] {-1, -1}; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0002_add_two_numbers/readme.md b/LeetCodeNet/G0001_0100/S0002_add_two_numbers/readme.md new file mode 100644 index 0000000..d36a527 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0002_add_two_numbers/readme.md @@ -0,0 +1,66 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 2\. Add Two Numbers + +Medium + +You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. + +You may assume the two numbers do not contain any leading zero, except the number 0 itself. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/10/02/addtwonumber1.jpg) + +**Input:** l1 = [2,4,3], l2 = [5,6,4] + +**Output:** [7,0,8] + +**Explanation:** 342 + 465 = 807. + +**Example 2:** + +**Input:** l1 = [0], l2 = [0] + +**Output:** [0] + +**Example 3:** + +**Input:** l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9] + +**Output:** [8,9,9,9,0,0,0,1] + +**Constraints:** + +* The number of nodes in each linked list is in the range `[1, 100]`. +* `0 <= Node.val <= 9` +* It is guaranteed that the list represents a number that does not have leading zeros. + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +public class Solution { + public ListNode AddTwoNumbers(ListNode l1, ListNode l2) { + ListNode dummyHead = new ListNode(0); + ListNode curr = dummyHead; + int carry = 0; + while (l1 != null || l2 != null) { + int x = (l1 != null) ? l1.val : 0; + int y = (l2 != null) ? l2.val : 0; + int sum = carry + x + y; + carry = sum / 10; + curr.next = new ListNode(sum % 10); + curr = curr.next; + if (l1 != null) l1 = l1.next; + if (l2 != null) l2 = l2.next; + } + if (carry > 0) { + curr.next = new ListNode(carry); + } + return dummyHead.next; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/readme.md b/LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/readme.md new file mode 100644 index 0000000..e2313f7 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters/readme.md @@ -0,0 +1,75 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 3\. Longest Substring Without Repeating Characters + +Medium + +Given a string `s`, find the length of the **longest substring** without repeating characters. + +**Example 1:** + +**Input:** s = "abcabcbb" + +**Output:** 3 + +**Explanation:** The answer is "abc", with the length of 3. + +**Example 2:** + +**Input:** s = "bbbbb" + +**Output:** 1 + +**Explanation:** The answer is "b", with the length of 1. + +**Example 3:** + +**Input:** s = "pwwkew" + +**Output:** 3 + +**Explanation:** The answer is "wke", with the length of 3. Notice that the answer must be a substring, "pwke" is a subsequence and not a substring. + +**Example 4:** + +**Input:** s = "" + +**Output:** 0 + +**Constraints:** + +* 0 <= s.length <= 5 * 104 +* `s` consists of English letters, digits, symbols and spaces. + +## Solution + +```csharp +public class Solution { + public int LengthOfLongestSubstring(string s) { + int[] lastIndices = new int[256]; + for (int i = 0; i < 256; i++) { + lastIndices[i] = -1; + } + int maxLen = 0; + int curLen = 0; + int start = 0; + for (int i = 0; i < s.Length; i++) { + char cur = s[i]; + if (lastIndices[cur] < start) { + lastIndices[cur] = i; + curLen++; + } else { + int lastIndex = lastIndices[cur]; + start = lastIndex + 1; + curLen = i - start + 1; + lastIndices[cur] = i; + } + if (curLen > maxLen) { + maxLen = curLen; + } + } + return maxLen; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/readme.md b/LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/readme.md new file mode 100644 index 0000000..5eac023 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays/readme.md @@ -0,0 +1,90 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 4\. Median of Two Sorted Arrays + +Hard + +Given two sorted arrays `nums1` and `nums2` of size `m` and `n` respectively, return **the median** of the two sorted arrays. + +The overall run time complexity should be `O(log (m+n))`. + +**Example 1:** + +**Input:** nums1 = [1,3], nums2 = [2] + +**Output:** 2.00000 + +**Explanation:** merged array = [1,2,3] and median is 2. + +**Example 2:** + +**Input:** nums1 = [1,2], nums2 = [3,4] + +**Output:** 2.50000 + +**Explanation:** merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5. + +**Example 3:** + +**Input:** nums1 = [0,0], nums2 = [0,0] + +**Output:** 0.00000 + +**Example 4:** + +**Input:** nums1 = [], nums2 = [1] + +**Output:** 1.00000 + +**Example 5:** + +**Input:** nums1 = [2], nums2 = [] + +**Output:** 2.00000 + +**Constraints:** + +* `nums1.length == m` +* `nums2.length == n` +* `0 <= m <= 1000` +* `0 <= n <= 1000` +* `1 <= m + n <= 2000` +* -106 <= nums1[i], nums2[i] <= 106 + +## Solution + +```csharp +public class Solution { + public double FindMedianSortedArrays(int[] nums1, int[] nums2) { + if (nums2.Length < nums1.Length) { + return FindMedianSortedArrays(nums2, nums1); + } + int cut1; + int cut2; + int n1 = nums1.Length; + int n2 = nums2.Length; + int low = 0; + int high = n1; + while (low <= high) { + cut1 = (low + high) / 2; + cut2 = ((n1 + n2 + 1) / 2) - cut1; + int l1 = cut1 == 0 ? int.MinValue : nums1[cut1 - 1]; + int l2 = cut2 == 0 ? int.MinValue : nums2[cut2 - 1]; + int r1 = cut1 == n1 ? int.MaxValue : nums1[cut1]; + int r2 = cut2 == n2 ? int.MaxValue : nums2[cut2]; + if (l1 <= r2 && l2 <= r1) { + if ((n1 + n2) % 2 == 0) { + return (Math.Max(l1, l2) + Math.Min(r1, r2)) / 2.0; + } + return Math.Max(l1, l2); + } else if (l1 > r2) { + high = cut1 - 1; + } else { + low = cut1 + 1; + } + } + return 0.0; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/readme.md b/LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/readme.md new file mode 100644 index 0000000..b746e4e --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring/readme.md @@ -0,0 +1,72 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 5\. Longest Palindromic Substring + +Medium + +Given a string `s`, return _the longest palindromic substring_ in `s`. + +**Example 1:** + +**Input:** s = "babad" + +**Output:** "bab" **Note:** "aba" is also a valid answer. + +**Example 2:** + +**Input:** s = "cbbd" + +**Output:** "bb" + +**Example 3:** + +**Input:** s = "a" + +**Output:** "a" + +**Example 4:** + +**Input:** s = "ac" + +**Output:** "a" + +**Constraints:** + +* `1 <= s.length <= 1000` +* `s` consist of only digits and English letters. + +## Solution + +```csharp +public class Solution { + public string LongestPalindrome(string s) { + if (s.Length == 1) return s; + int res = 0; + int l = 0; + int r = 0; + int len = s.Length; + for (int i = 0; i < len; i ++) { + for (int diff = 1; i - diff + 1 >= 0 && i + diff < len; diff ++) { + if (s[i - diff + 1] != s[i + diff]) break; + else if (res < diff * 2) { + res = diff * 2; + l = i - diff + 1; + r = i + diff; + } + } + } + for (int i = 0; i < len; i ++) { + for (int diff = 1; i - diff >= 0 && i + diff < len; diff ++) { + if (s[i - diff] != s[i + diff]) break; + else if (res < diff * 2 + 1) { + res = diff * 2 + 1; + l = i - diff; + r = i + diff; + } + } + } + return s.Substring(l, r - l + 1); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0006_zigzag_conversion/readme.md b/LeetCodeNet/G0001_0100/S0006_zigzag_conversion/readme.md new file mode 100644 index 0000000..5a0c1ae --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0006_zigzag_conversion/readme.md @@ -0,0 +1,79 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 6\. Zigzag Conversion + +Medium + +The string `"PAYPALISHIRING"` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) + +P A H N A P L S I I G Y I R + +And then read line by line: `"PAHNAPLSIIGYIR"` + +Write the code that will take a string and make this conversion given a number of rows: + +string convert(string s, int numRows); + +**Example 1:** + +**Input:** s = "PAYPALISHIRING", numRows = 3 + +**Output:** "PAHNAPLSIIGYIR" + +**Example 2:** + +**Input:** s = "PAYPALISHIRING", numRows = 4 + +**Output:** "PINALSIGYAHRPI" + +**Explanation:** P I N A L S I G Y A H R P I + +**Example 3:** + +**Input:** s = "A", numRows = 1 + +**Output:** "A" + +**Constraints:** + +* `1 <= s.length <= 1000` +* `s` consists of English letters (lower-case and upper-case), `','` and `'.'`. +* `1 <= numRows <= 1000` + +## Solution + +```csharp +using System.Text; + +public class Solution { + public string Convert(string s, int numRows) { + int sLen = s.Length; + if (numRows == 1) { + return s; + } + int maxDist = numRows * 2 - 2; + StringBuilder buf = new StringBuilder(); + for (int i = 0; i < numRows; i++) { + int index = i; + if (i == 0 || i == numRows - 1) { + while (index < sLen) { + buf.Append(s[index]); + index += maxDist; + } + } else { + while (index < sLen) { + buf.Append(s[index]); + index += maxDist - i * 2; + if (index >= sLen) { + break; + } + buf.Append(s[index]); + index += i * 2; + } + } + } + return buf.ToString(); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0007_reverse_integer/readme.md b/LeetCodeNet/G0001_0100/S0007_reverse_integer/readme.md new file mode 100644 index 0000000..8101300 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0007_reverse_integer/readme.md @@ -0,0 +1,56 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 7\. Reverse Integer + +Medium + +Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return `0`. + +**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).** + +**Example 1:** + +**Input:** x = 123 + +**Output:** 321 + +**Example 2:** + +**Input:** x = -123 + +**Output:** -321 + +**Example 3:** + +**Input:** x = 120 + +**Output:** 21 + +**Example 4:** + +**Input:** x = 0 + +**Output:** 0 + +**Constraints:** + +* -231 <= x <= 231 - 1 + +## Solution + +```csharp +public class Solution { + public int Reverse(int x) { + long rev = 0; + while (x != 0) { + rev = (rev * 10) + (x % 10); + x /= 10; + } + if (rev > int.MaxValue || rev < int.MinValue) { + return 0; + } + return (int) rev; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/readme.md b/LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/readme.md new file mode 100644 index 0000000..d0cf54c --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi/readme.md @@ -0,0 +1,160 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 8\. String to Integer (atoi) + +Medium + +Implement the `myAtoi(string s)` function, which converts a string to a 32-bit signed integer (similar to C/C++'s `atoi` function). + +The algorithm for `myAtoi(string s)` is as follows: + +1. Read in and ignore any leading whitespace. +2. Check if the next character (if not already at the end of the string) is `'-'` or `'+'`. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present. +3. Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored. +4. Convert these digits into an integer (i.e. `"123" -> 123`, `"0032" -> 32`). If no digits were read, then the integer is `0`. Change the sign as necessary (from step 2). +5. If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1. +6. Return the integer as the final result. + +**Note:** + +* Only the space character `' '` is considered a whitespace character. +* **Do not ignore** any characters other than the leading whitespace or the rest of the string after the digits. + +**Example 1:** + +**Input:** s = "42" + +**Output:** 42 + +**Explanation:** The underlined characters are what is read in, the caret is the current reader position. + + Step 1: "42" (no characters read because there is no leading whitespace) + ^ + Step 2: "42" (no characters read because there is neither a '-' nor '+') + ^ + Step 3: "42" ("42" is read in) + ^ + +The parsed integer is 42. Since 42 is in the range [-231, 231 - 1], the final result is 42. + +**Example 2:** + +**Input:** s = " -42" + +**Output:** -42 + +**Explanation:** + + Step 1: " -42" (leading whitespace is read and ignored) + ^ + Step 2: " -42" ('-' is read, so the result should be negative) + ^ + Step 3: " -42" ("42" is read in) + ^ + The parsed integer is -42. + +Since -42 is in the range [-231, 231 - 1], the final result is -42. + +**Example 3:** + +**Input:** s = "4193 with words" + +**Output:** 4193 + +**Explanation:** + + Step 1: "4193 with words" (no characters read because there is no leading whitespace) + ^ + Step 2: "4193 with words" (no characters read because there is neither a '-' nor '+') + ^ + Step 3: "4193 with words" ("4193" is read in; reading stops because the next character is a non-digit) + ^ + The parsed integer is 4193. + +Since 4193 is in the range [-231, 231 - 1], the final result is 4193. + +**Example 4:** + +**Input:** s = "words and 987" + +**Output:** 0 + +**Explanation:** + + Step 1: "words and 987" (no characters read because there is no leading whitespace) + ^ + Step 2: "words and 987" (no characters read because there is neither a '-' nor '+') + ^ + Step 3: "words and 987" (reading stops immediately because there is a non-digit 'w') + ^ + The parsed integer is 0 because no digits were read. + +Since 0 is in the range [-231, 231 - 1], the final result is 0. + +**Example 5:** + +**Input:** s = "-91283472332" + +**Output:** -2147483648 + +**Explanation:** + + Step 1: "-91283472332" (no characters read because there is no leading whitespace) + ^ + Step 2: "-91283472332" ('-' is read, so the result should be negative) + ^ + Step 3: "-91283472332" ("91283472332" is read in) + ^ + The parsed integer is -91283472332. + +Since -91283472332 is less than the lower bound of the range [-231, 231 - 1], the final result is clamped to -231 = -2147483648. + +**Constraints:** + +* `0 <= s.length <= 200` +* `s` consists of English letters (lower-case and upper-case), digits (`0-9`), `' '`, `'+'`, `'-'`, and `'.'`. + +## Solution + +```csharp +public class Solution { + public int MyAtoi(string str) { + if (str == null || str.Length == 0) { + return 0; + } + int i = 0; + bool negetiveSign = false; + char[] input = str.ToCharArray(); + while (i < input.Length && input[i] == ' ') { + i++; + } + if (i == input.Length) { + return 0; + } else if (input[i] == '+') { + i++; + } else if (input[i] == '-') { + i++; + negetiveSign = true; + } + int num = 0; + while (i < input.Length && input[i] <= '9' && input[i] >= '0') { + // current char + int tem = input[i] - '0'; + tem = negetiveSign ? -tem : tem; + // avoid invalid number like 038 + if (num == 0 && tem == '0') { + i++; + } else if (num == int.MinValue / 10 && tem <= -8 || num < int.MinValue / 10) { + return int.MinValue; + } else if (num == int.MaxValue / 10 && tem >= 7 || num > int.MaxValue / 10) { + return int.MaxValue; + } else { + num = num * 10 + tem; + i++; + } + } + return num; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0009_palindrome_number/readme.md b/LeetCodeNet/G0001_0100/S0009_palindrome_number/readme.md new file mode 100644 index 0000000..a36ccad --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0009_palindrome_number/readme.md @@ -0,0 +1,64 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 9\. Palindrome Number + +Easy + +Given an integer `x`, return `true` if `x` is palindrome integer. + +An integer is a **palindrome** when it reads the same backward as forward. For example, `121` is palindrome while `123` is not. + +**Example 1:** + +**Input:** x = 121 + +**Output:** true + +**Example 2:** + +**Input:** x = -121 + +**Output:** false + +**Explanation:** From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. + +**Example 3:** + +**Input:** x = 10 + +**Output:** false + +**Explanation:** Reads 01 from right to left. Therefore it is not a palindrome. + +**Example 4:** + +**Input:** x = -101 + +**Output:** false + +**Constraints:** + +* -231 <= x <= 231 - 1 + +**Follow up:** Could you solve it without converting the integer to a string? + +## Solution + +```csharp +public class Solution { + public bool IsPalindrome(int x) { + if (x < 0) { + return false; + } + int rev = 0; + int localX = x; + while (localX > 0) { + rev *= 10; + rev += localX % 10; + localX /= 10; + } + return rev == x; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0010_regular_expression_matching/readme.md b/LeetCodeNet/G0001_0100/S0010_regular_expression_matching/readme.md new file mode 100644 index 0000000..a15bbb4 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0010_regular_expression_matching/readme.md @@ -0,0 +1,90 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 10\. Regular Expression Matching + +Hard + +Given an input string `s` and a pattern `p`, implement regular expression matching with support for `'.'` and `'*'` where: + +* `'.'` Matches any single character. +* `'*'` Matches zero or more of the preceding element. + +The matching should cover the **entire** input string (not partial). + +**Example 1:** + +**Input:** s = "aa", p = "a" + +**Output:** false + +**Explanation:** "a" does not match the entire string "aa". + +**Example 2:** + +**Input:** s = "aa", p = "a\*" + +**Output:** true + +**Explanation:** '\*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa". + +**Example 3:** + +**Input:** s = "ab", p = ".\*" + +**Output:** true + +**Explanation:** ".\*" means "zero or more (\*) of any character (.)". + +**Example 4:** + +**Input:** s = "aab", p = "c\*a\*b" + +**Output:** true + +**Explanation:** c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches "aab". + +**Example 5:** + +**Input:** s = "mississippi", p = "mis\*is\*p\*." + +**Output:** false + +**Constraints:** + +* `1 <= s.length <= 20` +* `1 <= p.length <= 30` +* `s` contains only lowercase English letters. +* `p` contains only lowercase English letters, `'.'`, and `'*'`. +* It is guaranteed for each appearance of the character `'*'`, there will be a previous valid character to match. + +## Solution + +```csharp +public class Solution { + private bool?[,] cache; + + public bool IsMatch(string s, string p) { + cache = new bool?[s.Length + 1, p.Length + 1]; + return IsMatch(s, p, 0, 0); + } + + private bool IsMatch(string s, string p, int i, int j) { + if (j == p.Length) { + return i == s.Length; + } + bool result; + if (cache[i, j] != null) { + return cache[i, j].Value; + } + bool firstMatch = i < s.Length && (s[i] == p[j] || p[j] == '.'); + if ((j + 1) < p.Length && p[j + 1] == '*') { + result = (firstMatch && IsMatch(s, p, i + 1, j)) || IsMatch(s, p, i, j + 2); + } else { + result = firstMatch && IsMatch(s, p, i + 1, j + 1); + } + cache[i, j] = result; + return result; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0011_container_with_most_water/readme.md b/LeetCodeNet/G0001_0100/S0011_container_with_most_water/readme.md new file mode 100644 index 0000000..c1edb16 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0011_container_with_most_water/readme.md @@ -0,0 +1,68 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 11\. Container With Most Water + +Medium + +Given `n` non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). `n` vertical lines are drawn such that the two endpoints of the line `i` is at (i, ai) and `(i, 0)`. Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. + +**Notice** that you may not slant the container. + +**Example 1:** + +![](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg) + +**Input:** height = [1,8,6,2,5,4,8,3,7] + +**Output:** 49 + +**Explanation:** The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49. + +**Example 2:** + +**Input:** height = [1,1] + +**Output:** 1 + +**Example 3:** + +**Input:** height = [4,3,2,1,4] + +**Output:** 16 + +**Example 4:** + +**Input:** height = [1,2,1] + +**Output:** 2 + +**Constraints:** + +* `n == height.length` +* 2 <= n <= 105 +* 0 <= height[i] <= 104 + +## Solution + +```csharp +public class Solution { + public int MaxArea(int[] height) { + int maxArea = -1; + int left = 0; + int right = height.Length - 1; + + while (left < right) { + if (height[left] < height[right]) { + maxArea = Math.Max(maxArea, height[left] * (right - left)); + left++; + } else { + maxArea = Math.Max(maxArea, height[right] * (right - left)); + right--; + } + } + + return maxArea; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0015_3sum/readme.md b/LeetCodeNet/G0001_0100/S0015_3sum/readme.md new file mode 100644 index 0000000..f4ea44d --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0015_3sum/readme.md @@ -0,0 +1,80 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 15\. 3Sum + +Medium + +Given an integer array nums, return all the triplets `[nums[i], nums[j], nums[k]]` such that `i != j`, `i != k`, and `j != k`, and `nums[i] + nums[j] + nums[k] == 0`. + +Notice that the solution set must not contain duplicate triplets. + +**Example 1:** + +**Input:** nums = [-1,0,1,2,-1,-4] + +**Output:** [[-1,-1,2],[-1,0,1]] + +**Example 2:** + +**Input:** nums = [] + +**Output:** [] + +**Example 3:** + +**Input:** nums = [0] + +**Output:** [] + +**Constraints:** + +* `0 <= nums.length <= 3000` +* -105 <= nums[i] <= 105 + +## Solution + +```csharp +public class Solution { + public IList> ThreeSum(int[] nums) { + Array.Sort(nums); + int len = nums.Length; + IList> result = new List>(); + + for (int i = 0; i < len - 2; i++) { + int l = i + 1; + int r = len - 1; + + while (r > l) { + int sum = nums[i] + nums[l] + nums[r]; + + if (sum < 0) { + l++; + } else if (sum > 0) { + r--; + } else { + IList list = new List { nums[i], nums[l], nums[r] }; + result.Add(list); + + while (l < r && nums[l + 1] == nums[l]) { + l++; + } + + while (r > l && nums[r - 1] == nums[r]) { + r--; + } + + l++; + r--; + } + } + + while (i < len - 1 && nums[i + 1] == nums[i]) { + i++; + } + } + + return result; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/readme.md b/LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/readme.md new file mode 100644 index 0000000..263c3e6 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number/readme.md @@ -0,0 +1,71 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 17\. Letter Combinations of a Phone Number + +Medium + +Given a string containing digits from `2-9` inclusive, return all possible letter combinations that the number could represent. Return the answer in **any order**. + +A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. + +![](https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Telephone-keypad2.svg/200px-Telephone-keypad2.svg.png) + +**Example 1:** + +**Input:** digits = "23" + +**Output:** ["ad","ae","af","bd","be","bf","cd","ce","cf"] + +**Example 2:** + +**Input:** digits = "" + +**Output:** [] + +**Example 3:** + +**Input:** digits = "2" + +**Output:** ["a","b","c"] + +**Constraints:** + +* `0 <= digits.length <= 4` +* `digits[i]` is a digit in the range `['2', '9']`. + +## Solution + +```csharp +using System.Text; + +public class Solution { + public IList LetterCombinations(string digits) { + if (string.IsNullOrEmpty(digits)) { + return new List(); + } + string[] letters = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; + IList ans = new List(); + StringBuilder sb = new StringBuilder(); + FindCombinations(0, digits, letters, sb, ans); + return ans; + } + + private void FindCombinations( + int start, string nums, string[] letters, StringBuilder curr, IList ans) { + if (curr.Length == nums.Length) { + ans.Add(curr.ToString()); + return; + } + for (int i = start; i < nums.Length; i++) { + int n = int.Parse(nums[i].ToString()); + for (int j = 0; j < letters[n].Length; j++) { + char ch = letters[n][j]; + curr.Append(ch); + FindCombinations(i + 1, nums, letters, curr, ans); + curr.Length--; // Equivalent to deleting the last character in StringBuilder + } + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/readme.md b/LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/readme.md new file mode 100644 index 0000000..2383977 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list/readme.md @@ -0,0 +1,66 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 19\. Remove Nth Node From End of List + +Medium + +Given the `head` of a linked list, remove the `nth` node from the end of the list and return its head. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg) + +**Input:** head = [1,2,3,4,5], n = 2 + +**Output:** [1,2,3,5] + +**Example 2:** + +**Input:** head = [1], n = 1 + +**Output:** [] + +**Example 3:** + +**Input:** head = [1,2], n = 1 + +**Output:** [1] + +**Constraints:** + +* The number of nodes in the list is `sz`. +* `1 <= sz <= 30` +* `0 <= Node.val <= 100` +* `1 <= n <= sz` + +**Follow up:** Could you do this in one pass? + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +public class Solution { + private int n; + + public ListNode RemoveNthFromEnd(ListNode head, int n) { + this.n = n; + ListNode node = new ListNode(0, head); + RemoveNth(node); + return node.next; + } + + private void RemoveNth(ListNode node) { + if (node.next == null) { + return; + } + RemoveNth(node.next); + this.n--; + + if (this.n == 0) { + node.next = node.next.next; + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0020_valid_parentheses/readme.md b/LeetCodeNet/G0001_0100/S0020_valid_parentheses/readme.md new file mode 100644 index 0000000..854fb46 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0020_valid_parentheses/readme.md @@ -0,0 +1,76 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 20\. Valid Parentheses + +Easy + +Given a string `s` containing just the characters `'('`, `')'`, `'{'`, `'}'`, `'['` and `']'`, determine if the input string is valid. + +An input string is valid if: + +1. Open brackets must be closed by the same type of brackets. +2. Open brackets must be closed in the correct order. + +**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 + +**Constraints:** + +* 1 <= s.length <= 104 +* `s` consists of parentheses only `'()[]{}'`. + +## Solution + +```csharp +using System; +using System.Collections.Generic; + +public class Solution { + public bool IsValid(string s) { + Stack stack = new Stack(); + for (int i = 0; i < s.Length; i++) { + char c = s[i]; + if (c == '(' || c == '[' || c == '{') { + stack.Push(c); + } else if (c == ')' && stack.Count > 0 && stack.Peek() == '(') { + stack.Pop(); + } else if (c == '}' && stack.Count > 0 && stack.Peek() == '{') { + stack.Pop(); + } else if (c == ']' && stack.Count > 0 && stack.Peek() == '[') { + stack.Pop(); + } else { + return false; + } + } + return stack.Count == 0; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/readme.md b/LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/readme.md new file mode 100644 index 0000000..59db3ef --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists/readme.md @@ -0,0 +1,68 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 21\. Merge Two Sorted Lists + +Easy + +Merge two sorted linked lists and return it as a **sorted** list. The list should be made by splicing together the nodes of the first two lists. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/10/03/merge_ex1.jpg) + +**Input:** l1 = [1,2,4], l2 = [1,3,4] + +**Output:** [1,1,2,3,4,4] + +**Example 2:** + +**Input:** l1 = [], l2 = [] + +**Output:** [] + +**Example 3:** + +**Input:** l1 = [], l2 = [0] + +**Output:** [0] + +**Constraints:** + +* The number of nodes in both lists is in the range `[0, 50]`. +* `-100 <= Node.val <= 100` +* Both `l1` and `l2` are sorted in **non-decreasing** order. + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +public class Solution { + public ListNode MergeTwoLists(ListNode l1, ListNode l2) { + ListNode list = new ListNode(-1); + ListNode head = list; + + while (l1 != null || l2 != null) { + if (l1 != null && l2 != null) { + if (l1.val <= l2.val) { + list.next = new ListNode(l1.val); + l1 = l1.next; + } else { + list.next = new ListNode(l2.val); + l2 = l2.next; + } + } else if (l1 != null) { + list.next = new ListNode(l1.val); + l1 = l1.next; + } else { + list.next = new ListNode(l2.val); + l2 = l2.next; + } + list = list.next; + } + + return head.next; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0022_generate_parentheses/readme.md b/LeetCodeNet/G0001_0100/S0022_generate_parentheses/readme.md new file mode 100644 index 0000000..f443bc0 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0022_generate_parentheses/readme.md @@ -0,0 +1,57 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 22\. Generate Parentheses + +Medium + +Given `n` pairs of parentheses, write a function to _generate all combinations of well-formed parentheses_. + +**Example 1:** + +**Input:** n = 3 + +**Output:** ["((()))","(()())","(())()","()(())","()()()"] + +**Example 2:** + +**Input:** n = 1 + +**Output:** ["()"] + +**Constraints:** + +* `1 <= n <= 8` + +## Solution + +```csharp +using System.Collections.Generic; +using System.Text; + +public class Solution { + public IList GenerateParenthesis(int n) { + StringBuilder sb = new StringBuilder(); + List ans = new List(); + return Generate(sb, ans, n, n); + } + + private IList Generate(StringBuilder sb, List str, int open, int close) { + if (open == 0 && close == 0) { + str.Add(sb.ToString()); + return str; + } + if (open > 0) { + sb.Append('('); + Generate(sb, str, open - 1, close); + sb.Length--; // Equivalent to deleting the last character in StringBuilder + } + if (close > 0 && open < close) { + sb.Append(')'); + Generate(sb, str, open, close - 1); + sb.Length--; // Equivalent to deleting the last character in StringBuilder + } + return str; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/readme.md b/LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/readme.md new file mode 100644 index 0000000..5cad907 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists/readme.md @@ -0,0 +1,102 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 23\. Merge k Sorted Lists + +Hard + +You are given an array of `k` linked-lists `lists`, each linked-list is sorted in ascending order. + +_Merge all the linked-lists into one sorted linked-list and return it._ + +**Example 1:** + +**Input:** lists = \[\[1,4,5],[1,3,4],[2,6]] + +**Output:** [1,1,2,3,4,4,5,6] + +**Explanation:** The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into one sorted list: 1->1->2->3->4->4->5->6 + +**Example 2:** + +**Input:** lists = [] + +**Output:** [] + +**Example 3:** + +**Input:** lists = \[\[]] + +**Output:** [] + +**Constraints:** + +* `k == lists.length` +* `0 <= k <= 10^4` +* `0 <= lists[i].length <= 500` +* `-10^4 <= lists[i][j] <= 10^4` +* `lists[i]` is sorted in **ascending order**. +* The sum of `lists[i].length` won't exceed `10^4`. + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +public class Solution { + public ListNode MergeKLists(ListNode[] lists) { + if (lists.Length == 0) { + return null; + } + return MergeKLists(lists, 0, lists.Length); + } + + private ListNode MergeKLists(ListNode[] lists, int leftIndex, int rightIndex) { + if (rightIndex > leftIndex + 1) { + int mid = (leftIndex + rightIndex) / 2; + ListNode left = MergeKLists(lists, leftIndex, mid); + ListNode right = MergeKLists(lists, mid, rightIndex); + return MergeTwoLists(left, right); + } else { + return lists[leftIndex]; + } + } + + private ListNode MergeTwoLists(ListNode left, ListNode right) { + if (left == null) { + return right; + } + if (right == null) { + return left; + } + ListNode res; + if (left.val <= right.val) { + res = left; + left = left.next; + } else { + res = right; + right = right.next; + } + ListNode node = res; + while (left != null || right != null) { + if (left == null) { + node.next = right; + right = right.next; + } else if (right == null) { + node.next = left; + left = left.next; + } else { + if (left.val <= right.val) { + node.next = left; + left = left.next; + } else { + node.next = right; + right = right.next; + } + } + node = node.next; + } + return res; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/readme.md b/LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/readme.md new file mode 100644 index 0000000..5e7755e --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs/readme.md @@ -0,0 +1,78 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 24\. Swap Nodes in Pairs + +Medium + +Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.) + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/10/03/swap_ex1.jpg) + +**Input:** head = [1,2,3,4] + +**Output:** [2,1,4,3] + +**Example 2:** + +**Input:** head = [] + +**Output:** [] + +**Example 3:** + +**Input:** head = [1] + +**Output:** [1] + +**Constraints:** + +* The number of nodes in the list is in the range `[0, 100]`. +* `0 <= Node.val <= 100` + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +public class Solution { + public ListNode SwapPairs(ListNode head) { + if (head == null) { + return null; + } + int len = GetLength(head); + return Reverse(head, len); + } + + private int GetLength(ListNode curr) { + int cnt = 0; + while (curr != null) { + cnt++; + curr = curr.next; + } + return cnt; + } + + // Recursive function to reverse in groups + private ListNode Reverse(ListNode head, int len) { + // base case + if (len < 2) { + return head; + } + ListNode curr = head; + ListNode prev = null; + ListNode next; + for (int i = 0; i < 2; i++) { + // reverse linked list code + next = curr.next; + curr.next = prev; + prev = curr; + curr = next; + } + head.next = Reverse(curr, len - 2); + return prev; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/readme.md b/LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/readme.md new file mode 100644 index 0000000..be20f52 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group/readme.md @@ -0,0 +1,92 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 25\. Reverse Nodes in k-Group + +Hard + +Given a linked list, reverse the nodes of a linked list _k_ at a time and return its modified list. + +_k_ is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of _k_ then left-out nodes, in the end, should remain as it is. + +You may not alter the values in the list's nodes, only nodes themselves may be changed. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/10/03/reverse_ex1.jpg) + +**Input:** head = [1,2,3,4,5], k = 2 + +**Output:** [2,1,4,3,5] + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/10/03/reverse_ex2.jpg) + +**Input:** head = [1,2,3,4,5], k = 3 + +**Output:** [3,2,1,4,5] + +**Example 3:** + +**Input:** head = [1,2,3,4,5], k = 1 + +**Output:** [1,2,3,4,5] + +**Example 4:** + +**Input:** head = [1], k = 1 + +**Output:** [1] + +**Constraints:** + +* The number of nodes in the list is in the range `sz`. +* `1 <= sz <= 5000` +* `0 <= Node.val <= 1000` +* `1 <= k <= sz` + +**Follow-up:** Can you solve the problem in O(1) extra memory space? + +## Solution + +```csharp +using LeetCodeNet.Com_github_leetcode; + +public class Solution { + public ListNode ReverseKGroup(ListNode head, int k) { + if (head == null || head.next == null || k == 1) { + return head; + } + int j = 0; + ListNode len = head; + // loop for checking the length of the linked list, if the linked list is less than k, then return + // as it is. + while (j < k) { + if (len == null) { + return head; + } + len = len.next; + j++; + } + // Reverse linked list logic applied here. + ListNode c = head; + ListNode n = null; + ListNode prev = null; + int i = 0; + // Traverse the while loop for K times to reverse the nodes in K groups. + while (i != k) { + n = c.next; + c.next = prev; + prev = c; + c = n; + i++; + } + // `head` is pointing to the 1st node of the K group, which is now going to point to the next K group + // linked list. + // Recursion for further remaining linked list. + head.next = ReverseKGroup(n, k); + return prev; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0031_next_permutation/readme.md b/LeetCodeNet/G0001_0100/S0031_next_permutation/readme.md new file mode 100644 index 0000000..005b4c3 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0031_next_permutation/readme.md @@ -0,0 +1,77 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 31\. Next Permutation + +Medium + +Implement **next permutation**, which rearranges numbers into the lexicographically next greater permutation of numbers. + +If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order). + +The replacement must be **[in place](http://en.wikipedia.org/wiki/In-place_algorithm)** and use only constant extra memory. + +**Example 1:** + +**Input:** nums = [1,2,3] + +**Output:** [1,3,2] + +**Example 2:** + +**Input:** nums = [3,2,1] + +**Output:** [1,2,3] + +**Example 3:** + +**Input:** nums = [1,1,5] + +**Output:** [1,5,1] + +**Example 4:** + +**Input:** nums = [1] + +**Output:** [1] + +**Constraints:** + +* `1 <= nums.length <= 100` +* `0 <= nums[i] <= 100` + +## Solution + +```csharp +public class Solution { + public void NextPermutation(int[] nums) { + if (nums == null || nums.Length <= 1) { + return; + } + int i = nums.Length - 2; + while (i >= 0 && nums[i] >= nums[i + 1]) { + i--; + } + if (i >= 0) { + int j = nums.Length - 1; + while (nums[j] <= nums[i]) { + j--; + } + Swap(nums, i, j); + } + Reverse(nums, i + 1, nums.Length - 1); + } + + private void Swap(int[] nums, int i, int j) { + int temp = nums[i]; + nums[i] = nums[j]; + nums[j] = temp; + } + + private void Reverse(int[] nums, int i, int j) { + while (i < j) { + Swap(nums, i++, j--); + } + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/readme.md b/LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/readme.md new file mode 100644 index 0000000..2372de9 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses/readme.md @@ -0,0 +1,82 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 32\. Longest Valid Parentheses + +Hard + +Given a string containing just the characters `'('` and `')'`, find the length of the longest valid (well-formed) parentheses substring. + +**Example 1:** + +**Input:** s = "(()" + +**Output:** 2 + +**Explanation:** The longest valid parentheses substring is "()". + +**Example 2:** + +**Input:** s = ")()())" + +**Output:** 4 + +**Explanation:** The longest valid parentheses substring is "()()". + +**Example 3:** + +**Input:** s = "" + +**Output:** 0 + +**Constraints:** + +* 0 <= s.length <= 3 * 104 +* `s[i]` is `'('`, or `')'`. + +## Solution + +```csharp +public class Solution { + public int LongestValidParentheses(string s) { + int max = 0; + int left = 0; + int right = 0; + int n = s.Length; + char ch; + for (int i = 0; i < n; i++) { + ch = s[i]; + if (ch == '(') { + left++; + } else { + right++; + } + if (right > left) { + left = 0; + right = 0; + } + if (left == right) { + max = Math.Max(max, 2 * right); + } + } + left = 0; + right = 0; + for (int i = n - 1; i >= 0; i--) { + ch = s[i]; + if (ch == '(') { + left++; + } else { + right++; + } + if (left > right) { + left = 0; + right = 0; + } + if (left == right) { + max = Math.Max(max, 2 * left); + } + } + return max; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/readme.md b/LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/readme.md new file mode 100644 index 0000000..e42a161 --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array/readme.md @@ -0,0 +1,77 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 33\. Search in Rotated Sorted Array + +Medium + +There is an integer array `nums` sorted in ascending order (with **distinct** values). + +Prior to being passed to your function, `nums` is **possibly rotated** at an unknown pivot index `k` (`1 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (**0-indexed**). For example, `[0,1,2,4,5,6,7]` might be rotated at pivot index `3` and become `[4,5,6,7,0,1,2]`. + +Given the array `nums` **after** the possible rotation and an integer `target`, return _the index of_ `target` _if it is in_ `nums`_, or_ `-1` _if it is not in_ `nums`. + +You must write an algorithm with `O(log n)` runtime complexity. + +**Example 1:** + +**Input:** nums = [4,5,6,7,0,1,2], target = 0 + +**Output:** 4 + +**Example 2:** + +**Input:** nums = [4,5,6,7,0,1,2], target = 3 + +**Output:** -1 + +**Example 3:** + +**Input:** nums = [1], target = 0 + +**Output:** -1 + +**Constraints:** + +* `1 <= nums.length <= 5000` +* -104 <= nums[i] <= 104 +* All values of `nums` are **unique**. +* `nums` is an ascending array that is possibly rotated. +* -104 <= target <= 104 + +## Solution + +```csharp +public class Solution { + public int Search(int[] nums, int target) { + int mid; + int lo = 0; + int hi = nums.Length - 1; + while (lo <= hi) { + mid = ((hi - lo) >> 1) + lo; + if (target == nums[mid]) { + return mid; + } + // if this is true, then the possible rotation can only be in the second half + if (nums[lo] <= nums[mid]) { + // the target is in the first half only if it's + if (nums[lo] <= target && target <= nums[mid]) { + // included + hi = mid - 1; + } else { + // between nums[lo] and nums[mid] + lo = mid + 1; + } + // otherwise, the possible rotation can only be in the first half + } else if (nums[mid] <= target && target <= nums[hi]) { + // the target is in the second half only if it's included + lo = mid + 1; + } else { + // between nums[hi] and nums[mid] + hi = mid - 1; + } + } + return -1; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array/readme.md b/LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array/readme.md new file mode 100644 index 0000000..e9c393a --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array/readme.md @@ -0,0 +1,68 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 34\. Find First and Last Position of Element in Sorted Array + +Medium + +Given an array of integers `nums` sorted in non-decreasing order, find the starting and ending position of a given `target` value. + +If `target` is not found in the array, return `[-1, -1]`. + +You must write an algorithm with `O(log n)` runtime complexity. + +**Example 1:** + +**Input:** nums = [5,7,7,8,8,10], target = 8 + +**Output:** [3,4] + +**Example 2:** + +**Input:** nums = [5,7,7,8,8,10], target = 6 + +**Output:** [-1,-1] + +**Example 3:** + +**Input:** nums = [], target = 0 + +**Output:** [-1,-1] + +**Constraints:** + +* 0 <= nums.length <= 105 +* -109 <= nums[i] <= 109 +* `nums` is a non-decreasing array. +* -109 <= target <= 109 + +## Solution + +```csharp +public class Solution { + public int[] SearchRange(int[] nums, int target) { + int[] ans = new int[2]; + ans[0] = Helper(nums, target, false); + ans[1] = Helper(nums, target, true); + return ans; + } + + private int Helper(int[] nums, int target, bool equals) { + int l = 0; + int r = nums.Length - 1; + int result = -1; + while (l <= r) { + int mid = l + (r - l) / 2; + if (nums[mid] == target) { + result = mid; + } + if (nums[mid] < target || (nums[mid] == target && equals)) { + l = mid + 1; + } else { + r = mid - 1; + } + } + return result; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0035_search_insert_position/readme.md b/LeetCodeNet/G0001_0100/S0035_search_insert_position/readme.md new file mode 100644 index 0000000..6f40eeb --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0035_search_insert_position/readme.md @@ -0,0 +1,69 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 35\. Search Insert Position + +Easy + +Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. + +You must write an algorithm with `O(log n)` runtime complexity. + +**Example 1:** + +**Input:** nums = [1,3,5,6], target = 5 + +**Output:** 2 + +**Example 2:** + +**Input:** nums = [1,3,5,6], target = 2 + +**Output:** 1 + +**Example 3:** + +**Input:** nums = [1,3,5,6], target = 7 + +**Output:** 4 + +**Example 4:** + +**Input:** nums = [1,3,5,6], target = 0 + +**Output:** 0 + +**Example 5:** + +**Input:** nums = [1], target = 0 + +**Output:** 0 + +**Constraints:** + +* 1 <= nums.length <= 104 +* -104 <= nums[i] <= 104 +* `nums` contains **distinct** values sorted in **ascending** order. +* -104 <= target <= 104 + +## Solution + +```csharp +public class Solution { + public int SearchInsert(int[] nums, int target) { + int lo = 0; + int hi = nums.Length - 1; + while (lo <= hi) { + int mid = lo + (hi - lo) / 2; + if (target == nums[mid]) { + return mid; + } else if (target < nums[mid]) { + hi = mid - 1; + } else if (target > nums[mid]) { + lo = mid + 1; + } + } + return lo; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0039_combination_sum/readme.md b/LeetCodeNet/G0001_0100/S0039_combination_sum/readme.md new file mode 100644 index 0000000..b295c8a --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0039_combination_sum/readme.md @@ -0,0 +1,87 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 39\. Combination Sum + +Medium + +Given an array of **distinct** integers `candidates` and a target integer `target`, return _a list of all **unique combinations** of_ `candidates` _where the chosen numbers sum to_ `target`_._ You may return the combinations in **any order**. + +The **same** number may be chosen from `candidates` an **unlimited number of times**. Two combinations are unique if the frequency of at least one of the chosen numbers is different. + +It is **guaranteed** that the number of unique combinations that sum up to `target` is less than `150` combinations for the given input. + +**Example 1:** + +**Input:** candidates = [2,3,6,7], target = 7 + +**Output:** [[2,2,3],[7]] + +**Explanation:** + + 2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times. + 7 is a candidate, and 7 = 7. + These are the only two combinations. + +**Example 2:** + +**Input:** candidates = [2,3,5], target = 8 + +**Output:** [[2,2,2,2],[2,3,3],[3,5]] + +**Example 3:** + +**Input:** candidates = [2], target = 1 + +**Output:** [] + +**Example 4:** + +**Input:** candidates = [1], target = 1 + +**Output:** [[1]] + +**Example 5:** + +**Input:** candidates = [1], target = 2 + +**Output:** [[1,1]] + +**Constraints:** + +* `1 <= candidates.length <= 30` +* `1 <= candidates[i] <= 200` +* All elements of `candidates` are **distinct**. +* `1 <= target <= 500` + +## Solution + +```csharp +using System.Collections.Generic; + +public class Solution { + public IList> CombinationSum(int[] coins, int amount) { + IList> ans = new List>(); + List subList = new List(); + CombinationSumRec(coins.Length, coins, amount, subList, ans); + return ans; + } + + private void CombinationSumRec( + int n, int[] coins, int amount, List subList, IList> ans) { + if (amount == 0 || n == 0) { + if (amount == 0) { + List baseList = new List(subList); + ans.Add(baseList); + } + return; + } + if (amount - coins[n - 1] >= 0) { + subList.Add(coins[n - 1]); + CombinationSumRec(n, coins, amount - coins[n - 1], subList, ans); + subList.RemoveAt(subList.Count - 1); + } + CombinationSumRec(n - 1, coins, amount, subList, ans); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0041_first_missing_positive/readme.md b/LeetCodeNet/G0001_0100/S0041_first_missing_positive/readme.md new file mode 100644 index 0000000..c9529aa --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0041_first_missing_positive/readme.md @@ -0,0 +1,63 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 41\. First Missing Positive + +Hard + +Given an unsorted integer array `nums`, return the smallest missing positive integer. + +You must implement an algorithm that runs in `O(n)` time and uses constant extra space. + +**Example 1:** + +**Input:** nums = [1,2,0] + +**Output:** 3 + +**Example 2:** + +**Input:** nums = [3,4,-1,1] + +**Output:** 2 + +**Example 3:** + +**Input:** nums = [7,8,9,11,12] + +**Output:** 1 + +**Constraints:** + +* 1 <= nums.length <= 5 * 105 +* -231 <= nums[i] <= 231 - 1 + +## Solution + +```csharp +public class Solution { + public int FirstMissingPositive(int[] nums) { + for (int i = 0; i < nums.Length; i++) { + if (nums[i] <= 0 || nums[i] > nums.Length || nums[i] == i + 1) { + continue; + } + Dfs(nums, nums[i]); + } + for (int i = 0; i < nums.Length; i++) { + if (nums[i] != i + 1) { + return i + 1; + } + } + return nums.Length + 1; + } + + private void Dfs(int[] nums, int val) { + if (val <= 0 || val > nums.Length || val == nums[val - 1]) { + return; + } + int temp = nums[val - 1]; + nums[val - 1] = val; + Dfs(nums, temp); + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0042_trapping_rain_water/readme.md b/LeetCodeNet/G0001_0100/S0042_trapping_rain_water/readme.md new file mode 100644 index 0000000..51b2cac --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0042_trapping_rain_water/readme.md @@ -0,0 +1,67 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 42\. Trapping Rain Water + +Hard + +Given `n` non-negative integers representing an elevation map where the width of each bar is `1`, compute how much water it can trap after raining. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png) + +**Input:** height = [0,1,0,2,1,0,1,3,2,1,2,1] + +**Output:** 6 + +**Explanation:** The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. + +**Example 2:** + +**Input:** height = [4,2,0,3,2,5] + +**Output:** 9 + +**Constraints:** + +* `n == height.length` +* 1 <= n <= 2 * 104 +* 0 <= height[i] <= 105 + +## Solution + +```csharp +public class Solution { + public int Trap(int[] height) { + int l = 0; + int r = height.Length - 1; + int res = 0; + int lowerWall = 0; + while (l < r) { + int lVal = height[l]; + int rVal = height[r]; + // If left is smaller than right ptr, make the lower wall the bigger of lVal and its + // current size + if (lVal < rVal) { + // If lVal has gone up, move the lowerWall upp + lowerWall = System.Math.Max(lVal, lowerWall); + // Add the water level at current point + // Calculate this by taking the current value and subtracting it from the lower wall + // size + // We know that this is the lower wall because we've already determined that lVal < + // rVal + res += lowerWall - lVal; + // Move left ptr along + l++; + } else { + // Do the same thing, except now we know that the lowerWall is the right side. + lowerWall = System.Math.Max(rVal, lowerWall); + res += lowerWall - rVal; + r--; + } + } + return res; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0045_jump_game_ii/readme.md b/LeetCodeNet/G0001_0100/S0045_jump_game_ii/readme.md new file mode 100644 index 0000000..26388ed --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0045_jump_game_ii/readme.md @@ -0,0 +1,58 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 45\. Jump Game II + +Medium + +Given an array of non-negative integers `nums`, you are initially positioned at the first index of the array. + +Each element in the array represents your maximum jump length at that position. + +Your goal is to reach the last index in the minimum number of jumps. + +You can assume that you can always reach the last index. + +**Example 1:** + +**Input:** nums = [2,3,1,1,4] + +**Output:** 2 + +**Explanation:** The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index. + +**Example 2:** + +**Input:** nums = [2,3,0,1,4] + +**Output:** 2 + +**Constraints:** + +* 1 <= nums.length <= 104 +* `0 <= nums[i] <= 1000` + +## Solution + +```csharp +public class Solution { + public int Jump(int[] nums) { + int length = 0; + int maxLength = 0; + int minJump = 0; + for (int i = 0; i < nums.Length - 1; ++i) { + length--; + maxLength--; + maxLength = System.Math.Max(maxLength, nums[i]); + if (length <= 0) { + length = maxLength; + minJump++; + } + if (length >= nums.Length - i - 1) { + return minJump; + } + } + return minJump; + } +} +``` \ No newline at end of file diff --git a/LeetCodeNet/G0001_0100/S0046_permutations/readme.md b/LeetCodeNet/G0001_0100/S0046_permutations/readme.md new file mode 100644 index 0000000..2b7e4fa --- /dev/null +++ b/LeetCodeNet/G0001_0100/S0046_permutations/readme.md @@ -0,0 +1,67 @@ +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) + +## 46\. Permutations + +Medium + +Given an array `nums` of distinct integers, return _all the possible permutations_. You can return the answer in **any order**. + +**Example 1:** + +**Input:** nums = [1,2,3] + +**Output:** [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] + +**Example 2:** + +**Input:** nums = [0,1] + +**Output:** [[0,1],[1,0]] + +**Example 3:** + +**Input:** nums = [1] + +**Output:** [[1]] + +**Constraints:** + +* `1 <= nums.length <= 6` +* `-10 <= nums[i] <= 10` +* All the integers of `nums` are **unique**. + +## Solution + +```csharp +using System.Collections.Generic; + +public class Solution { + public IList> Permute(int[] nums) { + if (nums == null || nums.Length == 0) { + return new List>(); + } + IList> finalResult = new List>(); + PermuteRecur(nums, finalResult, new List(), new bool[nums.Length]); + return finalResult; + } + + private void PermuteRecur( + int[] nums, IList> finalResult, List currResult, bool[] used) { + if (currResult.Count == nums.Length) { + finalResult.Add(new List(currResult)); + return; + } + for (int i = 0; i < nums.Length; i++) { + if (used[i]) { + continue; + } + currResult.Add(nums[i]); + used[i] = true; + PermuteRecur(nums, finalResult, currResult, used); + used[i] = false; + currResult.RemoveAt(currResult.Count - 1); + } + } +} +``` \ No newline at end of file diff --git a/README.md b/README.md index 2c3f77a..c8f0c82 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,1286 @@ -# LeetCode-in-Net.github.io -C#-based LeetCode algorithm problem solutions, regularly updated. +[![](https://img.shields.io/github/stars/LeetCode-in-Net/LeetCode-in-Net?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net) +[![](https://img.shields.io/github/forks/LeetCode-in-Net/LeetCode-in-Net?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Net/LeetCode-in-Net/fork) +> ["For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby."](https://www.quora.com/How-effective-is-Leetcode-for-preparing-for-technical-interviews) + +* [Binary Search I](#binary-search-i) +* [Binary Search II](#binary-search-ii) +* [Dynamic Programming I](#dynamic-programming-i) +* [Programming Skills I](#programming-skills-i) +* [Programming Skills II](#programming-skills-ii) +* [Graph Theory I](#graph-theory-i) +* [SQL I](#sql-i) +* [Level 1](#level-1) +* [Level 2](#level-2) +* [Udemy](#udemy) +* [Data Structure I](#data-structure-i) +* [Data Structure II](#data-structure-ii) +* [Algorithm I](#algorithm-i) +* [Algorithm II](#algorithm-ii) + +### Binary Search I + +#### Day 1 + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 + +| | | | | | +|-|-|-|-|-|- +| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 106 | 6.17 + +#### Day 3 + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 + +| | | | | | +|-|-|-|-|-|- +| 0034 |[Find First and Last Position of Element in Sorted Array](LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 171 | 5.87 + +#### Day 6 + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 + +| | | | | | +|-|-|-|-|-|- +| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 + +#### Day 12 + +| | | | | | +|-|-|-|-|-|- + +### Binary Search II + +#### Day 1 + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 + +| | | | | | +|-|-|-|-|-|- + +#### Day 14 + +| | | | | | +|-|-|-|-|-|- + +#### Day 15 + +| | | | | | +|-|-|-|-|-|- + +#### Day 16 + +| | | | | | +|-|-|-|-|-|- + +#### Day 17 + +| | | | | | +|-|-|-|-|-|- + +#### Day 18 + +| | | | | | +|-|-|-|-|-|- + +#### Day 19 + +| | | | | | +|-|-|-|-|-|- + +#### Day 20 + +| | | | | | +|-|-|-|-|-|- + +### Dynamic Programming I + +#### Day 1 + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 + +| | | | | | +|-|-|-|-|-|- +| 0045 |[Jump Game II](LeetCodeNet/G0001_0100/S0045_jump_game_ii)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 144 | 15.35 + +#### Day 5 + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 + +| | | | | | +|-|-|-|-|-|- +| 0042 |[Trapping Rain Water](LeetCodeNet/G0001_0100/S0042_trapping_rain_water)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 81 | 89.96 + +#### Day 10 + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 + +| | | | | | +|-|-|-|-|-|- + +#### Day 14 + +| | | | | | +|-|-|-|-|-|- + +#### Day 15 + +| | | | | | +|-|-|-|-|-|- + +#### Day 16 + +| | | | | | +|-|-|-|-|-|- + +#### Day 17 + +| | | | | | +|-|-|-|-|-|- +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 + +#### Day 18 + +| | | | | | +|-|-|-|-|-|- + +#### Day 19 + +| | | | | | +|-|-|-|-|-|- + +#### Day 20 + +| | | | | | +|-|-|-|-|-|- + +#### Day 21 + +| | | | | | +|-|-|-|-|-|- + +### Programming Skills I + +#### Day 1 Basic Data Type + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 Operator + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 Conditional Statements + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 Loop + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 Function + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 String + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 String + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 Linked List and Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 Containers and Libraries + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 Class and Object + +| | | | | | +|-|-|-|-|-|- + +### Programming Skills II + +#### Day 1 + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 + +| | | | | | +|-|-|-|-|-|- + +#### Day 14 + +| | | | | | +|-|-|-|-|-|- + +#### Day 15 + +| | | | | | +|-|-|-|-|-|- +| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 84 | 77.30 + +#### Day 16 + +| | | | | | +|-|-|-|-|-|- + +#### Day 17 + +| | | | | | +|-|-|-|-|-|- + +#### Day 18 + +| | | | | | +|-|-|-|-|-|- + +#### Day 19 + +| | | | | | +|-|-|-|-|-|- + +#### Day 20 + +| | | | | | +|-|-|-|-|-|- + +### Graph Theory I + +#### Day 1 Matrix Related Problems + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 Matrix Related Problems + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 Matrix Related Problems + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 Matrix Related Problems + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 Matrix Related Problems + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 Matrix Related Problems + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 Standard Traversal + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 Standard Traversal + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 Standard Traversal + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 Standard Traversal + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 Breadth First Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 Breadth First Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 Graph Theory + +| | | | | | +|-|-|-|-|-|- + +#### Day 14 Graph Theory + +| | | | | | +|-|-|-|-|-|- + +### SQL I + +#### Day 1 Select + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 Select and Order + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 String Processing Functions + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 Union and Select + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 Union + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 Union + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 Function + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 Function + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 Control of Flow + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 Where + +| | | | | | +|-|-|-|-|-|- + +### Level 1 + +#### Day 1 Prefix Sum + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 String + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 + +#### Day 4 Linked List + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 Greedy + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 Binary Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 Binary Search Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 Graph/BFS/DFS + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 Sliding Window/Two Pointer + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 Hashmap + +| | | | | | +|-|-|-|-|-|- +| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 134 | 81.26 + +#### Day 14 Stack + +| | | | | | +|-|-|-|-|-|- + +#### Day 15 Heap + +| | | | | | +|-|-|-|-|-|- + +### Level 2 + +#### Day 1 Implementation/Simulation + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 String + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 69 | 90.79 + +#### Day 4 Linked List + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 Greedy + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 + +#### Day 9 Binary Search Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 Graph/BFS/DFS + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 Graph/BFS/DFS + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 14 Sliding Window/Two Pointer + +| | | | | | +|-|-|-|-|-|- +| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 50 | 98.40 + +#### Day 15 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 16 Design + +| | | | | | +|-|-|-|-|-|- + +#### Day 17 Interval + +| | | | | | +|-|-|-|-|-|- + +#### Day 18 Stack + +| | | | | | +|-|-|-|-|-|- + +#### Day 19 Union Find + +| | | | | | +|-|-|-|-|-|- + +#### Day 20 Brute Force/Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 94 | 99.60 +| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 148 | 5.56 + +### Udemy + +#### Udemy Integers + +| | | | | | +|-|-|-|-|-|- +| 0007 |[Reverse Integer](LeetCodeNet/G0001_0100/S0007_reverse_integer)| Medium | Top_Interview_Questions, Math | 23 | 59.02 +| 0009 |[Palindrome Number](LeetCodeNet/G0001_0100/S0009_palindrome_number)| Easy | Math | 42 | 34.61 + +#### Udemy Strings + +| | | | | | +|-|-|-|-|-|- +| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 50 | 98.40 +| 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 53 | 96.68 +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 + +#### Udemy Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 + +#### Udemy Arrays + +| | | | | | +|-|-|-|-|-|- +| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 134 | 81.26 +| 0041 |[First Missing Positive](LeetCodeNet/G0001_0100/S0041_first_missing_positive)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 192 | 13.98 + +#### Udemy Two Pointers + +| | | | | | +|-|-|-|-|-|- +| 0042 |[Trapping Rain Water](LeetCodeNet/G0001_0100/S0042_trapping_rain_water)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 81 | 89.96 +| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 173 | 75.85 + +#### Udemy Famous Algorithm + +| | | | | | +|-|-|-|-|-|- + +#### Udemy Sorting Algorithms + +| | | | | | +|-|-|-|-|-|- + +#### Udemy 2D Arrays/Matrix + +| | | | | | +|-|-|-|-|-|- + +#### Udemy Linked List + +| | | | | | +|-|-|-|-|-|- +| 0024 |[Swap Nodes in Pairs](LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 58 | 98.51 +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 +| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 75 | 86.97 + +#### Udemy Tree Stack Queue + +| | | | | | +|-|-|-|-|-|- + +#### Udemy Trie and Heap + +| | | | | | +|-|-|-|-|-|- + +#### Udemy Graph + +| | | | | | +|-|-|-|-|-|- + +#### Udemy Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0010 |[Regular Expression Matching](LeetCodeNet/G0001_0100/S0010_regular_expression_matching)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 59 | 96.10 + +#### Udemy Backtracking/Recursion + +| | | | | | +|-|-|-|-|-|- +| 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 81 | 99.57 +| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 94 | 99.60 +| 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 108 | 95.24 +| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 148 | 5.56 + +#### Udemy Bit Manipulation + +| | | | | | +|-|-|-|-|-|- + +#### Udemy Design + +| | | | | | +|-|-|-|-|-|- + +### Data Structure I + +#### Day 1 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 2 Array + +| | | | | | +|-|-|-|-|-|- +| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 134 | 81.26 + +#### Day 3 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 String + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 + +#### Day 8 Linked List + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 Stack Queue + +| | | | | | +|-|-|-|-|-|- +| 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 53 | 96.68 + +#### Day 10 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 11 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 14 Tree + +| | | | | | +|-|-|-|-|-|- + +### Data Structure II + +#### Day 1 Array + +| | | | | | +|-|-|-|-|-|- +| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 173 | 75.85 + +#### Day 2 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 Array + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 String + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 String + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 String + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 String + +| | | | | | +|-|-|-|-|-|- +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 + +#### Day 10 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 84 | 77.30 + +#### Day 11 Linked List + +| | | | | | +|-|-|-|-|-|- + +#### Day 12 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0024 |[Swap Nodes in Pairs](LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 58 | 98.51 + +#### Day 13 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 75 | 86.97 + +#### Day 14 Stack Queue + +| | | | | | +|-|-|-|-|-|- + +#### Day 15 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 16 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 17 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 18 Tree + +| | | | | | +|-|-|-|-|-|- + +#### Day 19 Graph + +| | | | | | +|-|-|-|-|-|- + +#### Day 20 Heap Priority Queue + +| | | | | | +|-|-|-|-|-|- + +#### Day 21 Heap Priority Queue + +| | | | | | +|-|-|-|-|-|- + +### Algorithm I + +#### Day 1 Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 106 | 6.17 + +#### Day 2 Two Pointers + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 Two Pointers + +| | | | | | +|-|-|-|-|-|- + +#### Day 4 Two Pointers + +| | | | | | +|-|-|-|-|-|- + +#### Day 5 Two Pointers + +| | | | | | +|-|-|-|-|-|- +| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 69 | 90.79 + +#### Day 6 Sliding Window + +| | | | | | +|-|-|-|-|-|- +| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 50 | 98.40 + +#### Day 7 Breadth First Search Depth First Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 Breadth First Search Depth First Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 Breadth First Search Depth First Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 Recursion Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 + +#### Day 11 Recursion Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 148 | 5.56 + +#### Day 12 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 Bit Manipulation + +| | | | | | +|-|-|-|-|-|- + +#### Day 14 Bit Manipulation + +| | | | | | +|-|-|-|-|-|- + +### Algorithm II + +#### Day 1 Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0034 |[Find First and Last Position of Element in Sorted Array](LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 171 | 5.87 +| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 + +#### Day 2 Binary Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 3 Two Pointers + +| | | | | | +|-|-|-|-|-|- +| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 173 | 75.85 + +#### Day 4 Two Pointers + +| | | | | | +|-|-|-|-|-|- +| 0011 |[Container With Most Water](LeetCodeNet/G0001_0100/S0011_container_with_most_water)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 248 | 11.15 + +#### Day 5 Sliding Window + +| | | | | | +|-|-|-|-|-|- + +#### Day 6 Breadth First Search Depth First Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 7 Breadth First Search Depth First Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 8 Breadth First Search Depth First Search + +| | | | | | +|-|-|-|-|-|- + +#### Day 9 Recursion Backtracking + +| | | | | | +|-|-|-|-|-|- + +#### Day 10 Recursion Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 94 | 99.60 + +#### Day 11 Recursion Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 108 | 95.24 +| 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 81 | 99.57 + +#### Day 12 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 13 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0045 |[Jump Game II](LeetCodeNet/G0001_0100/S0045_jump_game_ii)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 144 | 15.35 + +#### Day 14 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 + +#### Day 15 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 16 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 17 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 18 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- + +#### Day 19 Bit Manipulation + +| | | | | | +|-|-|-|-|-|- + +#### Day 20 Others + +| | | | | | +|-|-|-|-|-|- + +#### Day 21 Others + +| | | | | | +|-|-|-|-|-|- + +## Algorithms + +| # | Title | Difficulty | Tag | Time, ms | Time, % +|------|----------------|-------------|-------------|----------|-------- +| 0046 |[Permutations](LeetCodeNet/G0001_0100/S0046_permutations)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Algorithm_I_Day_11_Recursion_Backtracking, Level_2_Day_20_Brute_Force/Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 148 | 5.56 +| 0045 |[Jump Game II](LeetCodeNet/G0001_0100/S0045_jump_game_ii)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Algorithm_II_Day_13_Dynamic_Programming, Dynamic_Programming_I_Day_4, Big_O_Time_O(n)_Space_O(1) | 144 | 15.35 +| 0042 |[Trapping Rain Water](LeetCodeNet/G0001_0100/S0042_trapping_rain_water)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Dynamic_Programming_I_Day_9, Udemy_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 81 | 89.96 +| 0041 |[First Missing Positive](LeetCodeNet/G0001_0100/S0041_first_missing_positive)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 192 | 13.98 +| 0039 |[Combination Sum](LeetCodeNet/G0001_0100/S0039_combination_sum)| Medium | Top_100_Liked_Questions, Array, Backtracking, Algorithm_II_Day_10_Recursion_Backtracking, Level_2_Day_20_Brute_Force/Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n+2^n) | 94 | 99.60 +| 0035 |[Search Insert Position](LeetCodeNet/G0001_0100/S0035_search_insert_position)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Algorithm_I_Day_1_Binary_Search, Binary_Search_I_Day_2, Big_O_Time_O(log_n)_Space_O(1) | 106 | 6.17 +| 0034 |[Find First and Last Position of Element in Sorted Array](LeetCodeNet/G0001_0100/S0034_find_first_and_last_position_of_element_in_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_5, Big_O_Time_O(log_n)_Space_O(1) | 171 | 5.87 +| 0033 |[Search in Rotated Sorted Array](LeetCodeNet/G0001_0100/S0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_11, Level_2_Day_8_Binary_Search, Udemy_Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 63 | 96.89 +| 0032 |[Longest Valid Parentheses](LeetCodeNet/G0001_0100/S0032_longest_valid_parentheses)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Stack, Big_O_Time_O(n)_Space_O(1) | 49 | 96.18 +| 0031 |[Next Permutation](LeetCodeNet/G0001_0100/S0031_next_permutation)| Medium | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 202 | 5.19 +| 0025 |[Reverse Nodes in k-Group](LeetCodeNet/G0001_0100/S0025_reverse_nodes_in_k_group)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_13_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(k) | 75 | 86.97 +| 0024 |[Swap Nodes in Pairs](LeetCodeNet/G0001_0100/S0024_swap_nodes_in_pairs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_12_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(1) | 58 | 98.51 +| 0023 |[Merge k Sorted Lists](LeetCodeNet/G0001_0100/S0023_merge_k_sorted_lists)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Heap_Priority_Queue, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 78 | 98.24 +| 0022 |[Generate Parentheses](LeetCodeNet/G0001_0100/S0022_generate_parentheses)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n) | 81 | 99.57 +| 0021 |[Merge Two Sorted Lists](LeetCodeNet/G0001_0100/S0021_merge_two_sorted_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Data_Structure_I_Day_7_Linked_List, Algorithm_I_Day_10_Recursion_Backtracking, Level_1_Day_3_Linked_List, Udemy_Linked_List, Big_O_Time_O(m+n)_Space_O(m+n) | 69 | 92.74 +| 0020 |[Valid Parentheses](LeetCodeNet/G0001_0100/S0020_valid_parentheses)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Data_Structure_I_Day_9_Stack_Queue, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 53 | 96.68 +| 0019 |[Remove Nth Node From End of List](LeetCodeNet/G0001_0100/S0019_remove_nth_node_from_end_of_list)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Algorithm_I_Day_5_Two_Pointers, Level_2_Day_3_Linked_List, Big_O_Time_O(L)_Space_O(L) | 69 | 90.79 +| 0017 |[Letter Combinations of a Phone Number](LeetCodeNet/G0001_0100/S0017_letter_combinations_of_a_phone_number)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(4^n)_Space_O(n) | 108 | 95.24 +| 0015 |[3Sum](LeetCodeNet/G0001_0100/S0015_3sum)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_1_Array, Algorithm_II_Day_3_Two_Pointers, Udemy_Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 173 | 75.85 +| 0011 |[Container With Most Water](LeetCodeNet/G0001_0100/S0011_container_with_most_water)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Algorithm_II_Day_4_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 248 | 11.15 +| 0010 |[Regular Expression Matching](LeetCodeNet/G0001_0100/S0010_regular_expression_matching)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 59 | 96.10 +| 0009 |[Palindrome Number](LeetCodeNet/G0001_0100/S0009_palindrome_number)| Easy | Math, Udemy_Integers | 42 | 34.61 +| 0008 |[String to Integer (atoi)](LeetCodeNet/G0001_0100/S0008_string_to_integer_atoi)| Medium | Top_Interview_Questions, String | 43 | 99.83 +| 0007 |[Reverse Integer](LeetCodeNet/G0001_0100/S0007_reverse_integer)| Medium | Top_Interview_Questions, Math, Udemy_Integers | 23 | 59.02 +| 0006 |[Zigzag Conversion](LeetCodeNet/G0001_0100/S0006_zigzag_conversion)| Medium | String | 59 | 99.87 +| 0005 |[Longest Palindromic Substring](LeetCodeNet/G0001_0100/S0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Data_Structure_II_Day_9_String, Algorithm_II_Day_14_Dynamic_Programming, Dynamic_Programming_I_Day_17, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 61 | 99.50 +| 0004 |[Median of Two Sorted Arrays](LeetCodeNet/G0001_0100/S0004_median_of_two_sorted_arrays)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Big_O_Time_O(log(min(N,M)))_Space_O(1) | 83 | 96.35 +| 0003 |[Longest Substring Without Repeating Characters](LeetCodeNet/G0001_0100/S0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Algorithm_I_Day_6_Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Udemy_Strings, Big_O_Time_O(n)_Space_O(1) | 50 | 98.40 +| 0002 |[Add Two Numbers](LeetCodeNet/G0001_0100/S0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Data_Structure_II_Day_10_Linked_List, Programming_Skills_II_Day_15, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 84 | 77.30 +| 0001 |[Two Sum](LeetCodeNet/G0001_0100/S0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Data_Structure_I_Day_2_Array, Level_1_Day_13_Hashmap, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 134 | 81.26 +