Skip to content

Commit 71d9cff

Browse files
authored
Updated readme
1 parent 6dd36d5 commit 71d9cff

File tree

11 files changed

+780
-0
lines changed

11 files changed

+780
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333

3434
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
3535
|-|-|-|-|-|-
36+
| 0015 |[3Sum](src/main/ruby/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) | 659 | 83.74
3637

3738
#### Day 4 Two Pointers
3839

3940
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
4041
|-|-|-|-|-|-
42+
| 0011 |[Container With Most Water](src/main/ruby/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) | 114 | 95.98
4143

4244
#### Day 5 Sliding Window
4345

@@ -73,6 +75,8 @@
7375

7476
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
7577
|-|-|-|-|-|-
78+
| 0017 |[Letter Combinations of a Phone Number](src/main/ruby/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) | 49 | 93.94
79+
| 0022 |[Generate Parentheses](src/main/ruby/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) | 43 | 100.00
7680

7781
#### Day 12 Dynamic Programming
7882

@@ -702,6 +706,7 @@
702706

703707
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
704708
|-|-|-|-|-|-
709+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/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) | 66 | 59.01
705710

706711
#### Day 4 Linked List
707712

@@ -780,6 +785,7 @@
780785

781786
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
782787
|-|-|-|-|-|-
788+
| 0019 |[Remove Nth Node From End of List](src/main/ruby/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) | 51 | 95.27
783789

784790
#### Day 4 Linked List
785791

@@ -881,6 +887,7 @@
881887
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
882888
|-|-|-|-|-|-
883889
| 0003 |[Longest Substring Without Repeating Characters](src/main/ruby/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) | 94 | 85.62
890+
| 0020 |[Valid Parentheses](src/main/ruby/g0001_0100/s0020_valid_parentheses)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 53 | 90.52
884891
| 0005 |[Longest Palindromic Substring](src/main/ruby/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) | 117 | 98.63
885892

886893
#### Udemy Binary Search
@@ -898,6 +905,7 @@
898905

899906
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
900907
|-|-|-|-|-|-
908+
| 0015 |[3Sum](src/main/ruby/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) | 659 | 83.74
901909

902910
#### Udemy Famous Algorithm
903911

@@ -918,6 +926,9 @@
918926

919927
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
920928
|-|-|-|-|-|-
929+
| 0024 |[Swap Nodes in Pairs](src/main/ruby/g0001_0100/s0024_swap_nodes_in_pairs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 59 | 76.00
930+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/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) | 66 | 59.01
931+
| 0025 |[Reverse Nodes in k-Group](src/main/ruby/g0001_0100/s0025_reverse_nodes_in_k_group)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 62 | 91.67
921932

922933
#### Udemy Tree Stack Queue
923934

@@ -944,6 +955,8 @@
944955

945956
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
946957
|-|-|-|-|-|-
958+
| 0022 |[Generate Parentheses](src/main/ruby/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) | 43 | 100.00
959+
| 0017 |[Letter Combinations of a Phone Number](src/main/ruby/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) | 49 | 93.94
947960

948961
#### Udemy Bit Manipulation
949962

@@ -992,6 +1005,7 @@
9921005

9931006
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
9941007
|-|-|-|-|-|-
1008+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/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) | 66 | 59.01
9951009

9961010
#### Day 8 Linked List
9971011

@@ -1002,6 +1016,7 @@
10021016

10031017
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10041018
|-|-|-|-|-|-
1019+
| 0020 |[Valid Parentheses](src/main/ruby/g0001_0100/s0020_valid_parentheses)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 53 | 90.52
10051020

10061021
#### Day 10 Tree
10071022

@@ -1034,6 +1049,7 @@
10341049

10351050
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10361051
|-|-|-|-|-|-
1052+
| 0015 |[3Sum](src/main/ruby/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) | 659 | 83.74
10371053

10381054
#### Day 2 Array
10391055

@@ -1091,11 +1107,13 @@
10911107

10921108
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10931109
|-|-|-|-|-|-
1110+
| 0024 |[Swap Nodes in Pairs](src/main/ruby/g0001_0100/s0024_swap_nodes_in_pairs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 59 | 76.00
10941111

10951112
#### Day 13 Linked List
10961113

10971114
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10981115
|-|-|-|-|-|-
1116+
| 0025 |[Reverse Nodes in k-Group](src/main/ruby/g0001_0100/s0025_reverse_nodes_in_k_group)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 62 | 91.67
10991117

11001118
#### Day 14 Stack Queue
11011119

@@ -1163,6 +1181,7 @@
11631181

11641182
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11651183
|-|-|-|-|-|-
1184+
| 0019 |[Remove Nth Node From End of List](src/main/ruby/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) | 51 | 95.27
11661185

11671186
#### Day 6 Sliding Window
11681187

@@ -1189,6 +1208,7 @@
11891208

11901209
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11911210
|-|-|-|-|-|-
1211+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/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) | 66 | 59.01
11921212

11931213
#### Day 11 Recursion Backtracking
11941214

@@ -1214,6 +1234,16 @@
12141234

12151235
| # | Title | Difficulty | Tag | Time, ms | Time, %
12161236
|------|----------------|-------------|-------------|----------|--------
1237+
| 0025 |[Reverse Nodes in k-Group](src/main/ruby/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) | 62 | 91.67
1238+
| 0024 |[Swap Nodes in Pairs](src/main/ruby/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) | 59 | 76.00
1239+
| 0023 |[Merge k Sorted Lists](src/main/ruby/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)) | 76 | 87.95
1240+
| 0022 |[Generate Parentheses](src/main/ruby/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) | 43 | 100.00
1241+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/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) | 66 | 59.01
1242+
| 0020 |[Valid Parentheses](src/main/ruby/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 | 90.52
1243+
| 0019 |[Remove Nth Node From End of List](src/main/ruby/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) | 51 | 95.27
1244+
| 0017 |[Letter Combinations of a Phone Number](src/main/ruby/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) | 49 | 93.94
1245+
| 0015 |[3Sum](src/main/ruby/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) | 659 | 83.74
1246+
| 0011 |[Container With Most Water](src/main/ruby/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) | 114 | 95.98
12171247
| 0010 |[Regular Expression Matching](src/main/ruby/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) | 66 | 94.44
12181248
| 0009 |[Palindrome Number](src/main/ruby/g0001_0100/s0009_palindrome_number)| Easy | Math, Udemy_Integers | 83 | 74.19
12191249
| 0008 |[String to Integer (atoi)](src/main/ruby/g0001_0100/s0008_string_to_integer_atoi)| Medium | Top_Interview_Questions, String | 67 | 67.26
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-Ruby/LeetCode-in-Ruby?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Ruby/LeetCode-in-Ruby)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-Ruby/LeetCode-in-Ruby?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Ruby/LeetCode-in-Ruby/fork)
3+
4+
## 11\. Container With Most Water
5+
6+
Medium
7+
8+
Given `n` non-negative integers <code>a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub></code> , where each represents a point at coordinate <code>(i, a<sub>i</sub>)</code>. `n` vertical lines are drawn such that the two endpoints of the line `i` is at <code>(i, a<sub>i</sub>)</code> and `(i, 0)`. Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.
9+
10+
**Notice** that you may not slant the container.
11+
12+
**Example 1:**
13+
14+
![](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg)
15+
16+
**Input:** height = [1,8,6,2,5,4,8,3,7]
17+
18+
**Output:** 49
19+
20+
**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.
21+
22+
**Example 2:**
23+
24+
**Input:** height = [1,1]
25+
26+
**Output:** 1
27+
28+
**Example 3:**
29+
30+
**Input:** height = [4,3,2,1,4]
31+
32+
**Output:** 16
33+
34+
**Example 4:**
35+
36+
**Input:** height = [1,2,1]
37+
38+
**Output:** 2
39+
40+
**Constraints:**
41+
42+
* `n == height.length`
43+
* <code>2 <= n <= 10<sup>5</sup></code>
44+
* <code>0 <= height[i] <= 10<sup>4</sup></code>
45+
46+
## Solution
47+
48+
```ruby
49+
# @param {Integer[]} height
50+
# @return {Integer}
51+
def max_area(height)
52+
max_area = -1
53+
left = 0
54+
right = height.length - 1
55+
56+
while left < right
57+
if height[left] < height[right]
58+
max_area = [max_area, height[left] * (right - left)].max
59+
left += 1
60+
else
61+
max_area = [max_area, height[right] * (right - left)].max
62+
right -= 1
63+
end
64+
end
65+
66+
max_area
67+
end
68+
```
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-Ruby/LeetCode-in-Ruby?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Ruby/LeetCode-in-Ruby)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-Ruby/LeetCode-in-Ruby?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Ruby/LeetCode-in-Ruby/fork)
3+
4+
## 15\. 3Sum
5+
6+
Medium
7+
8+
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`.
9+
10+
Notice that the solution set must not contain duplicate triplets.
11+
12+
**Example 1:**
13+
14+
**Input:** nums = [-1,0,1,2,-1,-4]
15+
16+
**Output:** [[-1,-1,2],[-1,0,1]]
17+
18+
**Example 2:**
19+
20+
**Input:** nums = []
21+
22+
**Output:** []
23+
24+
**Example 3:**
25+
26+
**Input:** nums = [0]
27+
28+
**Output:** []
29+
30+
**Constraints:**
31+
32+
* `0 <= nums.length <= 3000`
33+
* <code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code>
34+
35+
## Solution
36+
37+
```ruby
38+
# @param {Integer[]} nums
39+
# @return {Integer[][]}
40+
def three_sum(nums)
41+
nums = nums.sort
42+
rs = []
43+
nums.each.with_index do |num, i|
44+
if i > 0 && num == nums[i - 1]
45+
next
46+
end
47+
l, r = i + 1, nums.size - 1
48+
49+
while l < r
50+
sum = num + nums[l] + nums[r]
51+
if sum > 0
52+
r -= 1
53+
elsif sum < 0
54+
l += 1
55+
else
56+
rs << [num, nums[l], nums[r]]
57+
l += 1
58+
while nums[l] == nums[l - 1] && l < r
59+
l += 1
60+
end
61+
end
62+
end
63+
end
64+
65+
rs
66+
end
67+
```
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-Ruby/LeetCode-in-Ruby?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Ruby/LeetCode-in-Ruby)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-Ruby/LeetCode-in-Ruby?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Ruby/LeetCode-in-Ruby/fork)
3+
4+
## 17\. Letter Combinations of a Phone Number
5+
6+
Medium
7+
8+
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**.
9+
10+
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
11+
12+
![](https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Telephone-keypad2.svg/200px-Telephone-keypad2.svg.png)
13+
14+
**Example 1:**
15+
16+
**Input:** digits = "23"
17+
18+
**Output:** ["ad","ae","af","bd","be","bf","cd","ce","cf"]
19+
20+
**Example 2:**
21+
22+
**Input:** digits = ""
23+
24+
**Output:** []
25+
26+
**Example 3:**
27+
28+
**Input:** digits = "2"
29+
30+
**Output:** ["a","b","c"]
31+
32+
**Constraints:**
33+
34+
* `0 <= digits.length <= 4`
35+
* `digits[i]` is a digit in the range `['2', '9']`.
36+
37+
## Solution
38+
39+
```ruby
40+
# @param {String} digits
41+
# @return {String[]}
42+
def letter_combinations(digits)
43+
return [] if digits.empty?
44+
45+
letters = ["", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]
46+
ans = []
47+
find_combinations(0, digits, letters, "", ans)
48+
ans
49+
end
50+
51+
private
52+
53+
def find_combinations(start, nums, letters, curr, ans)
54+
if curr.length == nums.length
55+
ans << curr
56+
return
57+
end
58+
59+
(start...nums.length).each do |i|
60+
n = nums[i].to_i
61+
letters[n].each_char do |ch|
62+
find_combinations(i + 1, nums, letters, curr + ch, ans)
63+
end
64+
end
65+
end
66+
```

0 commit comments

Comments
 (0)