Skip to content

Commit 0ee1e7c

Browse files
authored
Updated tags for tasks 41-48
1 parent 4167ce4 commit 0ee1e7c

File tree

9 files changed

+24
-32
lines changed

9 files changed

+24
-32
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22

33
Hard
44

5-
Given an unsorted integer array `nums`, return the smallest missing positive integer.
5+
Given an unsorted integer array `nums`. Return the _smallest positive integer_ that is _not present_ in `nums`.
66

7-
You must implement an algorithm that runs in `O(n)` time and uses constant extra space.
7+
You must implement an algorithm that runs in `O(n)` time and uses `O(1)` auxiliary space.
88

99
**Example 1:**
1010

1111
**Input:** nums = [1,2,0]
1212

1313
**Output:** 3
1414

15-
**Explanation:** The numbers in the range [1,2] are all in the array.
15+
**Explanation:** The numbers in the range [1,2] are all in the array.
1616

1717
**Example 2:**
1818

1919
**Input:** nums = [3,4,-1,1]
2020

2121
**Output:** 2
2222

23-
**Explanation:** 1 is in the array but 2 is missing.
23+
**Explanation:** 1 is in the array but 2 is missing.
2424

2525
**Example 3:**
2626

2727
**Input:** nums = [7,8,9,11,12]
2828

2929
**Output:** 1
3030

31-
**Explanation:** The smallest positive integer 1 is missing.
31+
**Explanation:** The smallest positive integer 1 is missing.
3232

3333
**Constraints:**
3434

Original file line numberDiff line numberDiff line change
@@ -1,42 +1,37 @@
11
package s0041_first_missing_positive
22

33
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Udemy_Arrays
4-
// #Big_O_Time_O(n)_Space_O(n) #2024_03_12_Time_39_ms_(92.34%)_Space_7.8_MB_(79.50%)
4+
// #Big_O_Time_O(n)_Space_O(n) #2025_05_03_Time_0_ms_(100.00%)_Space_9.49_MB_(95.52%)
55

66
func firstMissingPositive(nums []int) int {
77
for i := 0; i < len(nums); i++ {
88
if nums[i] < 0 {
99
nums[i] = 0
1010
}
1111
}
12-
1312
for i := 0; i < len(nums); i++ {
1413
val := abs(nums[i])
1514
if val > 0 && val <= len(nums) {
1615
if nums[val-1] > 0 {
1716
nums[val-1] = nums[val-1] * -1
1817
continue
1918
}
20-
2119
if nums[val-1] == 0 {
2220
nums[val-1] = -1 * (len(nums) + 1)
2321
}
2422
}
2523
}
26-
2724
for i := 1; i <= len(nums); i++ {
2825
if nums[i-1] >= 0 {
2926
return i
3027
}
3128
}
32-
3329
return len(nums) + 1
3430
}
3531

3632
func abs(n int) int {
3733
if n >= 0 {
3834
return n
3935
}
40-
4136
return n * -1
4237
}

src/main/go/g0001_0100/s0042_trapping_rain_water/solution.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package s0042_trapping_rain_water
33
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming #Two_Pointers
44
// #Stack #Monotonic_Stack #Dynamic_Programming_I_Day_9 #Udemy_Two_Pointers
55
// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1)
6-
// #2024_03_12_Time_3_ms_(99.42%)_Space_5.4_MB_(97.01%)
6+
// #2025_05_03_Time_0_ms_(100.00%)_Space_7.85_MB_(82.53%)
77

88
func trap(height []int) int {
99
if height == nil {

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22

33
Medium
44

5-
Given an array of non-negative integers `nums`, you are initially positioned at the first index of the array.
5+
You are given a **0-indexed** array of integers `nums` of length `n`. You are initially positioned at `nums[0]`.
66

7-
Each element in the array represents your maximum jump length at that position.
7+
Each element `nums[i]` represents the maximum length of a forward jump from index `i`. In other words, if you are at `nums[i]`, you can jump to any `nums[i + j]` where:
88

9-
Your goal is to reach the last index in the minimum number of jumps.
9+
* `0 <= j <= nums[i]` and
10+
* `i + j < n`
1011

11-
You can assume that you can always reach the last index.
12+
Return _the minimum number of jumps to reach_ `nums[n - 1]`. The test cases are generated such that you can reach `nums[n - 1]`.
1213

1314
**Example 1:**
1415

1516
**Input:** nums = [2,3,1,1,4]
1617

1718
**Output:** 2
1819

19-
**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.
20+
**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.
2021

2122
**Example 2:**
2223

2324
**Input:** nums = [2,3,0,1,4]
2425

25-
**Output:** 2
26+
**Output:** 2
2627

2728
**Constraints:**
2829

2930
* <code>1 <= nums.length <= 10<sup>4</sup></code>
30-
* `0 <= nums[i] <= 1000`
31+
* `0 <= nums[i] <= 1000`
32+
* It's guaranteed that you can reach `nums[n - 1]`.

src/main/go/g0001_0100/s0045_jump_game_ii/solution.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package s0045_jump_game_ii
33
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Greedy
44
// #Algorithm_II_Day_13_Dynamic_Programming #Dynamic_Programming_I_Day_4
55
// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1)
6-
// #2024_03_12_Time_6_ms_(96.98%)_Space_6.3_MB_(34.53%)
6+
// #2025_05_03_Time_0_ms_(100.00%)_Space_7.78_MB_(85.74%)
77

88
func jump(nums []int) int {
99
length := 0

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
Medium
44

5-
Given an array `nums` of distinct integers, return _all the possible permutations_. You can return the answer in **any order**.
5+
Given an array `nums` of distinct integers, return all the possible permutations. You can return the answer in **any order**.
66

77
**Example 1:**
88

99
**Input:** nums = [1,2,3]
1010

11-
**Output:** [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
11+
**Output:** [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
1212

1313
**Example 2:**
1414

1515
**Input:** nums = [0,1]
1616

17-
**Output:** [[0,1],[1,0]]
17+
**Output:** [[0,1],[1,0]]
1818

1919
**Example 3:**
2020

2121
**Input:** nums = [1]
2222

23-
**Output:** [[1]]
23+
**Output:** [[1]]
2424

2525
**Constraints:**
2626

src/main/go/g0001_0100/s0046_permutations/solution.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package s0046_permutations
33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Backtracking
44
// #Algorithm_I_Day_11_Recursion_Backtracking #Level_2_Day_20_Brute_Force/Backtracking
55
// #Udemy_Backtracking/Recursion #Top_Interview_150_Backtracking #Big_O_Time_O(n*n!)_Space_O(n+n!)
6-
// #2024_03_12_Time_0_ms_(100.00%)_Space_2.7_MB_(51.79%)
6+
// #2025_05_03_Time_0_ms_(100.00%)_Space_4.59_MB_(85.96%)
77

88
func permute(nums []int) [][]int {
99
if len(nums) == 0 {

src/main/go/g0001_0100/s0048_rotate_image/solution.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package s0048_rotate_image
33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Matrix
44
// #Data_Structure_II_Day_3_Array #Programming_Skills_II_Day_7 #Udemy_2D_Arrays/Matrix
55
// #Top_Interview_150_Matrix #Big_O_Time_O(n^2)_Space_O(1)
6-
// #2024_03_12_Time_0_ms_(100.00%)_Space_2.3_MB_(75.46%)
6+
// #2025_05_03_Time_0_ms_(100.00%)_Space_4.06_MB_(97.99%)
77

88
func rotate(matrix [][]int) {
99
n := len(matrix)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package s0494_target_sum
22

33
// #Medium #Array #Dynamic_Programming #Backtracking #Big_O_Time_O(n*(sum+s))_Space_O(n*(sum+s))
4-
// #2024_03_12_Time_7_ms_(80.54%)_Space_6.6_MB_(40.47%)
4+
// #2025_04_30_Time_4_ms_(82.40%)_Space_8.36_MB_(41.63%)
55

66
import "math"
77

@@ -11,25 +11,21 @@ func findTargetSumWays(nums []int, s int) int {
1111
for _, num := range nums {
1212
sum += num
1313
}
14-
1514
if s > sum || (sum+s)%2 != 0 {
1615
return 0
1716
}
18-
1917
dp := make([][]int, (sum+s)/2+1)
2018
for i := range dp {
2119
dp[i] = make([]int, len(nums)+1)
2220
}
2321
dp[0][0] = 1
24-
2522
for i := 0; i < len(nums); i++ {
2623
if nums[i] == 0 {
2724
dp[0][i+1] = dp[0][i] * 2
2825
} else {
2926
dp[0][i+1] = dp[0][i]
3027
}
3128
}
32-
3329
for i := 1; i < len(dp); i++ {
3430
for j := 0; j < len(nums); j++ {
3531
dp[i][j+1] += dp[i][j]
@@ -38,6 +34,5 @@ func findTargetSumWays(nums []int, s int) int {
3834
}
3935
}
4036
}
41-
4237
return dp[(sum+s)/2][len(nums)]
4338
}

0 commit comments

Comments
 (0)