Skip to content

Commit a879b91

Browse files
committed
Updated Go tasks
1 parent d499e59 commit a879b91

File tree

118 files changed

+391
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+391
-388
lines changed

src/main/go/g0001_0100/s0001_two_sum/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ You can return the answer in any order.
3535
* <code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code>
3636
* **Only one valid answer exists.**
3737

38-
**Follow-up:** Can you come up with an algorithm that is less than <code>O(n<sup>2</sup>)</code> time complexity?
38+
**Follow-up:** Can you come up with an algorithm that is less than <code>O(n<sup>2</sup>)</code> time complexity?

src/main/go/g0001_0100/s0001_two_sum/solution.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package s0001_two_sum
22

33
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table
4-
// #Data_Structure_I_Day_2_Array #Level_1_Day_13_Hashmap #Udemy_Arrays #Big_O_Time_O(n)_Space_O(n)
5-
// #2024_01_28_Time_3_ms_(93.85%)_Space_4.2_MB_(58.64%)
4+
// #Data_Structure_I_Day_2_Array #Level_1_Day_13_Hashmap #Udemy_Arrays #Top_Interview_150_Hashmap
5+
// #Big_O_Time_O(n)_Space_O(n) #AI_can_be_used_to_solve_the_task
6+
// #2025_04_27_Time_0_ms_(100.00%)_Space_5.85_MB_(61.87%)
67

78
func twoSum(nums []int, target int) []int {
89
indexMap := make(map[int]int)

src/main/go/g0001_0100/s0002_add_two_numbers/solution.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package s0002_add_two_numbers
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Math #Linked_List #Recursion
44
// #Data_Structure_II_Day_10_Linked_List #Programming_Skills_II_Day_15
5-
// #Big_O_Time_O(max(N,M))_Space_O(max(N,M)) #2024_03_05_Time_4_ms_(84.60%)_Space_4.4_MB_(47.97%)
5+
// #Top_Interview_150_Linked_List #Big_O_Time_O(max(N,M))_Space_O(max(N,M))
6+
// #AI_can_be_used_to_solve_the_task #2025_04_27_Time_0_ms_(100.00%)_Space_6.17_MB_(92.78%)
67

78
type ListNode struct {
89
Val int
@@ -20,7 +21,6 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
2021
dummyHead := &ListNode{}
2122
p, q, curr := l1, l2, dummyHead
2223
carry := 0
23-
2424
for p != nil || q != nil {
2525
x, y := 0, 0
2626
if p != nil {
@@ -31,16 +31,13 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
3131
y = q.Val
3232
q = q.Next
3333
}
34-
3534
sum := carry + x + y
3635
carry = sum / 10
3736
curr.Next = &ListNode{Val: sum % 10}
3837
curr = curr.Next
3938
}
40-
4139
if carry > 0 {
4240
curr.Next = &ListNode{Val: carry}
4341
}
44-
4542
return dummyHead.Next
4643
}

src/main/go/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Medium
44

5-
Given a string `s`, find the length of the **longest** **substring** without repeating characters.
5+
Given a string `s`, find the length of the **longest** **substring** without duplicate characters.
66

77
**Example 1:**
88

src/main/go/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package s0003_longest_substring_without_repeating_characters
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Sliding_Window
44
// #Algorithm_I_Day_6_Sliding_Window #Level_2_Day_14_Sliding_Window/Two_Pointer #Udemy_Strings
5-
// #Big_O_Time_O(n)_Space_O(1) #2024_03_05_Time_0_ms_(100.00%)_Space_2.5_MB_(98.66%)
5+
// #Top_Interview_150_Sliding_Window #Big_O_Time_O(n)_Space_O(1) #AI_can_be_used_to_solve_the_task
6+
// #2025_04_27_Time_0_ms_(100.00%)_Space_4.45_MB_(94.51%)
67

78
func lengthOfLongestSubstring(s string) int {
89
lastIndices := make([]int, 256)

src/main/go/g0001_0100/s0004_median_of_two_sorted_arrays/solution.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
package s0004_median_of_two_sorted_arrays
22

33
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Divide_and_Conquer
4-
// #Big_O_Time_O(log(min(N,M)))_Space_O(1) #2024_03_05_Time_9_ms_(72.04%)_Space_4.8_MB_(67.69%)
4+
// #Top_Interview_150_Binary_Search #Big_O_Time_O(log(min(N,M)))_Space_O(1)
5+
// #AI_can_be_used_to_solve_the_task #2025_04_27_Time_0_ms_(100.00%)_Space_6.51_MB_(81.58%)
56

67
func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {
78
if len(nums1) > len(nums2) {
89
nums1, nums2 = nums2, nums1
910
}
10-
1111
x, y := len(nums1), len(nums2)
1212
low, high := 0, x
13-
1413
for low <= high {
1514
partitionX := (low + high) / 2
1615
partitionY := (x+y+1)/2 - partitionX
17-
1816
maxLeftX := getIntValue(nums1, partitionX-1)
1917
minRightX := getIntValue(nums1, partitionX)
20-
2118
maxLeftY := getIntValue(nums2, partitionY-1)
2219
minRightY := getIntValue(nums2, partitionY)
23-
2420
if maxLeftX <= minRightY && maxLeftY <= minRightX {
2521
if (x+y)%2 == 0 {
2622
return float64(max(maxLeftX, maxLeftY)+min(minRightX, minRightY)) / 2
@@ -33,7 +29,6 @@ func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {
3329
low = partitionX + 1
3430
}
3531
}
36-
3732
return 0.0
3833
}
3934

src/main/go/g0001_0100/s0005_longest_palindromic_substring/solution.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package s0005_longest_palindromic_substring
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming
44
// #Data_Structure_II_Day_9_String #Algorithm_II_Day_14_Dynamic_Programming
5-
// #Dynamic_Programming_I_Day_17 #Udemy_Strings #Big_O_Time_O(n)_Space_O(n)
6-
// #2024_03_05_Time_0_ms_(100.00%)_Space_3.8_MB_(32.56%)
5+
// #Dynamic_Programming_I_Day_17 #Udemy_Strings #Top_Interview_150_Multidimensional_DP
6+
// #Big_O_Time_O(n)_Space_O(n) #2025_04_27_Time_0_ms_(100.00%)_Space_5.76_MB_(29.62%)
77

88
func longestPalindrome(s string) string {
99
newStr := make([]byte, len(s)*2+1)
@@ -15,7 +15,6 @@ func longestPalindrome(s string) string {
1515
dp := make([]int, len(newStr))
1616
friendCenter, friendRadius := 0, 0
1717
lpsCenter, lpsRadius := 0, 0
18-
1918
for i := 0; i < len(newStr); i++ {
2019
if friendCenter+friendRadius > i {
2120
dp[i] = min(dp[2*friendCenter-i], (friendCenter+friendRadius)-i)

src/main/go/g0001_0100/s0006_zigzag_conversion/solution.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package s0006_zigzag_conversion
22

3-
// #Medium #String #2024_03_05_Time_0_ms_(100.00%)_Space_4_MB_(86.83%)
3+
// #Medium #String #Top_Interview_150_Array/String
4+
// #2025_04_27_Time_0_ms_(100.00%)_Space_5.75_MB_(95.79%)
45

56
func convert(s string, numRows int) string {
67
topJump := (numRows-2)*2 + 2

src/main/go/g0001_0100/s0007_reverse_integer/solution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package s0007_reverse_integer
22

33
// #Medium #Top_Interview_Questions #Math #Udemy_Integers
4-
// #2024_03_07_Time_0_ms_(100.00%)_Space_2.2_MB_(46.99%)
4+
// #2025_04_27_Time_0_ms_(100.00%)_Space_4.03_MB_(24.37%)
55

66
import "math"
77

src/main/go/g0001_0100/s0008_string_to_integer_atoi/solution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package s0008_string_to_integer_atoi
22

3-
// #Medium #Top_Interview_Questions #String #2024_03_07_Time_0_ms_(100.00%)_Space_2.3_MB_(27.02%)
3+
// #Medium #Top_Interview_Questions #String #2025_04_27_Time_0_ms_(100.00%)_Space_4.07_MB_(99.22%)
44

55
import (
66
"math"

src/main/go/g0001_0100/s0009_palindrome_number/solution.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package s0009_palindrome_number
22

3-
// #Easy #Math #Udemy_Integers #2024_03_07_Time_0_ms_(100.00%)_Space_4.3_MB_(99.46%)
3+
// #Easy #Math #Udemy_Integers #Top_Interview_150_Math
4+
// #2025_04_27_Time_0_ms_(100.00%)_Space_5.96_MB_(99.06%)
45

56
func isPalindrome(x int) bool {
67
if x < 10 {

src/main/go/g0001_0100/s0010_regular_expression_matching/solution.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package s0010_regular_expression_matching
22

3-
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming #Recursion
4-
// #Udemy_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n)
5-
// #2024_03_07_Time_0_ms_(100.00%)_Space_2.3_MB_(36.02%)
3+
// #Hard #Top_Interview_Questions #String #Dynamic_Programming #Recursion #Udemy_Dynamic_Programming
4+
// #Big_O_Time_O(m*n)_Space_O(m*n) #2025_04_27_Time_0_ms_(100.00%)_Space_4.20_MB_(84.42%)
65

76
func isMatch(s string, p string) bool {
87
m, n := len(s), len(p)

src/main/go/g0001_0100/s0011_container_with_most_water/solution.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
package s0011_container_with_most_water
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Greedy #Two_Pointers
4-
// #Algorithm_II_Day_4_Two_Pointers #Big_O_Time_O(n)_Space_O(1)
5-
// #2024_03_07_Time_60_ms_(94.99%)_Space_8.3_MB_(24.10%)
4+
// #LeetCode_75_Two_Pointers #Algorithm_II_Day_4_Two_Pointers #Top_Interview_150_Two_Pointers
5+
// #Big_O_Time_O(n)_Space_O(1) #2025_04_27_Time_0_ms_(100.00%)_Space_9.30_MB_(86.74%)
66

77
func maxArea(height []int) int {
88
l, r := 0, len(height)-1
99
maxArea := 0
10-
1110
for l < r {
1211
area := min(height[l], height[r]) * (r - l)
1312
if area > maxArea {
1413
maxArea = area
1514
}
16-
1715
if height[l] < height[r] {
1816
l++
1917
} else {
2018
r--
2119
}
2220
}
23-
2421
return maxArea
2522
}
2623

src/main/go/g0001_0100/s0015_3sum/solution.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package s0015_3sum
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Two_Pointers
44
// #Data_Structure_II_Day_1_Array #Algorithm_II_Day_3_Two_Pointers #Udemy_Two_Pointers
5-
// #Big_O_Time_O(n*log(n))_Space_O(n^2) #2024_03_07_Time_37_ms_(90.03%)_Space_7.9_MB_(46.68%)
5+
// #Top_Interview_150_Two_Pointers #Big_O_Time_O(n*log(n))_Space_O(n^2)
6+
// #2025_04_27_Time_12_ms_(99.83%)_Space_9.72_MB_(48.62%)
67

78
import "sort"
89

src/main/go/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package s0017_letter_combinations_of_a_phone_number
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Backtracking
4-
// #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion
5-
// #Big_O_Time_O(4^n)_Space_O(n) #2024_03_07_Time_0_ms_(100.00%)_Space_2.1_MB_(87.39%)
4+
// #LeetCode_75_Backtracking #Algorithm_II_Day_11_Recursion_Backtracking
5+
// #Udemy_Backtracking/Recursion #Top_Interview_150_Backtracking #Big_O_Time_O(4^n)_Space_O(n)
6+
// #2025_04_27_Time_0_ms_(100.00%)_Space_3.96_MB_(93.28%)
67

78
func letterCombinations(digits string) []string {
89
if len(digits) == 0 {
@@ -20,7 +21,6 @@ func findCombinations(start int, nums string, letters []string, curr *string, an
2021
*ans = append(*ans, *curr)
2122
return
2223
}
23-
2424
for i := start; i < len(nums); i++ {
2525
n := int(nums[i] - '0')
2626
for j := 0; j < len(letters[n]); j++ {

src/main/go/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package s0019_remove_nth_node_from_end_of_list
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Two_Pointers #Linked_List
4-
// #Algorithm_I_Day_5_Two_Pointers #Level_2_Day_3_Linked_List #Big_O_Time_O(L)_Space_O(L)
5-
// #2024_03_07_Time_0_ms_(100.00%)_Space_2.2_MB_(19.66%)
4+
// #Algorithm_I_Day_5_Two_Pointers #Level_2_Day_3_Linked_List #Top_Interview_150_Linked_List
5+
// #Big_O_Time_O(L)_Space_O(L) #2025_04_27_Time_0_ms_(100.00%)_Space_4.16_MB_(48.09%)
66

77
type ListNode struct {
88
Val int

src/main/go/g0001_0100/s0020_valid_parentheses/solution.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package s0020_valid_parentheses
22

33
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Stack
4-
// #Data_Structure_I_Day_9_Stack_Queue #Udemy_Strings #Big_O_Time_O(n)_Space_O(n)
5-
// #2024_03_07_Time_1_ms_(74.95%)_Space_2_MB_(68.19%)
4+
// #Data_Structure_I_Day_9_Stack_Queue #Udemy_Strings #Top_Interview_150_Stack
5+
// #Big_O_Time_O(n)_Space_O(n) #2025_04_27_Time_0_ms_(100.00%)_Space_4.27_MB_(35.78%)
66

77
func isValid(s string) bool {
88
stack := make([]rune, 0)
@@ -27,6 +27,5 @@ func isValid(s string) bool {
2727
stack = stack[:len(stack)-1]
2828
}
2929
}
30-
3130
return len(stack) == 0
3231
}

src/main/go/g0001_0100/s0021_merge_two_sorted_lists/solution.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package s0021_merge_two_sorted_lists
22

33
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion
44
// #Data_Structure_I_Day_7_Linked_List #Algorithm_I_Day_10_Recursion_Backtracking
5-
// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(m+n)_Space_O(m+n)
6-
// #2024_03_07_Time_0_ms_(100.00%)_Space_2.5_MB_(95.02%)
5+
// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List
6+
// #Big_O_Time_O(m+n)_Space_O(m+n) #2025_04_27_Time_0_ms_(100.00%)_Space_4.48_MB_(40.41%)
77

88
type ListNode struct {
99
Val int
@@ -19,7 +19,6 @@ type ListNode struct {
1919
*/
2020
func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {
2121
var sortedListNode, tail *ListNode = &ListNode{}, &ListNode{}
22-
2322
// Start sortedListNode and tail node at the same position
2423
tail = sortedListNode
2524
for list1 != nil && list2 != nil {
@@ -33,14 +32,11 @@ func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {
3332
// Progress the tail further
3433
tail = tail.Next
3534
}
36-
3735
if list1 != nil {
3836
tail.Next = list1
3937
}
40-
4138
if list2 != nil {
4239
tail.Next = list2
4340
}
44-
4541
return sortedListNode.Next
4642
}

src/main/go/g0001_0100/s0022_generate_parentheses/solution.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package s0022_generate_parentheses
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming
44
// #Backtracking #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion
5-
// #Big_O_Time_O(2^n)_Space_O(n) #2024_03_08_Time_2_ms_(75.02%)_Space_2.8_MB_(72.29%)
5+
// #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n)
6+
// #2025_04_27_Time_0_ms_(100.00%)_Space_4.66_MB_(78.73%)
67

78
func generateParenthesis(n int) []string {
89
result := []string{}
@@ -15,7 +16,6 @@ func generate(s string, start, close, n int, result *[]string) {
1516
*result = append(*result, s)
1617
return
1718
}
18-
1919
if start < n {
2020
generate(s+"(", start+1, close, n, result)
2121
}

src/main/go/g0001_0100/s0023_merge_k_sorted_lists/readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ _Merge all the linked-lists into one sorted linked-list and return it._
1212

1313
**Output:** [1,1,2,3,4,4,5,6]
1414

15-
**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
15+
**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
1616

1717
**Example 2:**
1818

1919
**Input:** lists = []
2020

21-
**Output:** []
21+
**Output:** []
2222

2323
**Example 3:**
2424

2525
**Input:** lists = [[]]
2626

27-
**Output:** []
27+
**Output:** []
2828

2929
**Constraints:**
3030

3131
* `k == lists.length`
32-
* `0 <= k <= 10^4`
32+
* <code>0 <= k <= 10<sup>4</sup></code>
3333
* `0 <= lists[i].length <= 500`
34-
* `-10^4 <= lists[i][j] <= 10^4`
34+
* <code>-10<sup>4</sup> <= lists[i][j] <= 10<sup>4</sup></code>
3535
* `lists[i]` is sorted in **ascending order**.
36-
* The sum of `lists[i].length` won't exceed `10^4`.
36+
* The sum of `lists[i].length` will not exceed <code>10<sup>4</sup></code>.

src/main/go/g0001_0100/s0023_merge_k_sorted_lists/solution.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package s0023_merge_k_sorted_lists
22

3-
import "container/heap"
4-
53
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Heap_Priority_Queue #Linked_List
6-
// #Divide_and_Conquer #Merge_Sort #Big_O_Time_O(k*n*log(k))_Space_O(log(k))
7-
// #2024_03_08_Time_3_ms_(96.74%)_Space_5.5_MB_(25.28%)
4+
// #Divide_and_Conquer #Merge_Sort #Top_Interview_150_Divide_and_Conquer
5+
// #Big_O_Time_O(k*n*log(k))_Space_O(log(k)) #2025_04_27_Time_0_ms_(100.00%)_Space_7.12_MB_(27.34%)
6+
7+
import "container/heap"
88

99
type ListNode struct {
1010
Val int

src/main/go/g0001_0100/s0024_swap_nodes_in_pairs/readme.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ Given a linked list, swap every two adjacent nodes and return its head. You must
66

77
**Example 1:**
88

9-
![](https://assets.leetcode.com/uploads/2020/10/03/swap_ex1.jpg)
10-
119
**Input:** head = [1,2,3,4]
1210

1311
**Output:** [2,1,4,3]
1412

13+
**Explanation:**
14+
15+
![](https://assets.leetcode.com/uploads/2020/10/03/swap_ex1.jpg)
16+
1517
**Example 2:**
1618

1719
**Input:** head = []
@@ -24,6 +26,12 @@ Given a linked list, swap every two adjacent nodes and return its head. You must
2426

2527
**Output:** [1]
2628

29+
**Example 4:**
30+
31+
**Input:** head = [1,2,3]
32+
33+
**Output:** [2,1,3]
34+
2735
**Constraints:**
2836

2937
* The number of nodes in the list is in the range `[0, 100]`.

0 commit comments

Comments
 (0)