Skip to content

Updated tag for tasks 139-208 #1866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions src/main/java/g0101_0200/s0139_word_break/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,36 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table
// #Dynamic_Programming #Trie #Memoization #Algorithm_II_Day_15_Dynamic_Programming
// #Dynamic_Programming_I_Day_9 #Udemy_Dynamic_Programming #Big_O_Time_O(M+max*N)_Space_O(M+N+max)
// #2022_06_24_Time_2_ms_(97.08%)_Space_42.1_MB_(90.92%)
// #2024_11_15_Time_1_ms_(99.42%)_Space_42.1_MB_(80.42%)

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution {
private Boolean[] memo;

public boolean wordBreak(String s, List<String> wordDict) {
Set<String> set = new HashSet<>();
int max = 0;
boolean[] flag = new boolean[s.length() + 1];
for (String st : wordDict) {
set.add(st);
if (max < st.length()) {
max = st.length();
}
}
for (int i = 1; i <= max; i++) {
if (dfs(s, 0, i, max, set, flag)) {
return true;
}
}
return false;
memo = new Boolean[s.length() + 1];
return dp(s, 0, wordDict);
}

private boolean dfs(String s, int start, int end, int max, Set<String> set, boolean[] flag) {
if (!flag[end] && set.contains(s.substring(start, end))) {
flag[end] = true;
if (end == s.length()) {
return true;
public boolean dp(String s, int i, List<String> wordDict) {
if (i == s.length()) {
return true;
}
if (memo[i] != null) {
return memo[i];
}
for (String word : wordDict) {
int len = word.length();
if (i + len > s.length() || !s.substring(i, i + len).equals(word)) {
continue;
}
for (int i = 1; i <= max; i++) {
if (end + i <= s.length() && dfs(s, end, end + i, max, set, flag)) {
return true;
}
if (dp(s, i + len, wordDict)) {
memo[i] = true;
return true;
}
}
memo[i] = false;
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List
// #Data_Structure_I_Day_7_Linked_List #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(1)
// #2022_06_24_Time_0_ms_(100.00%)_Space_45.5_MB_(68.52%)
// #2024_11_15_Time_0_ms_(100.00%)_Space_44.3_MB_(52.46%)

import com_github_leetcode.ListNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Hash_Table #Two_Pointers #Linked_List
// #Data_Structure_II_Day_10_Linked_List #Level_1_Day_4_Linked_List #Udemy_Linked_List
// #Big_O_Time_O(N)_Space_O(1) #2022_06_24_Time_0_ms_(100.00%)_Space_42.3_MB_(98.70%)
// #Big_O_Time_O(N)_Space_O(1) #2024_11_15_Time_0_ms_(100.00%)_Space_44.7_MB_(20.31%)

import com_github_leetcode.ListNode;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/g0101_0200/s0146_lru_cache/LRUCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Design #Linked_List
// #Doubly_Linked_List #Udemy_Linked_List #Big_O_Time_O(1)_Space_O(capacity)
// #2022_06_24_Time_87_ms_(50.80%)_Space_125.2_MB_(58.73%)
// #2024_11_15_Time_40_ms_(98.20%)_Space_111.4_MB_(88.70%)

import java.util.HashMap;
import java.util.Map;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/g0101_0200/s0148_sort_list/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Sorting #Two_Pointers #Linked_List
// #Divide_and_Conquer #Merge_Sort #Level_2_Day_4_Linked_List #Big_O_Time_O(log(N))_Space_O(log(N))
// #2022_06_24_Time_12_ms_(85.82%)_Space_76_MB_(43.84%)
// #2024_11_15_Time_9_ms_(93.90%)_Space_56.9_MB_(37.47%)

import com_github_leetcode.ListNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
// #Dynamic_Programming_I_Day_6 #Level_2_Day_13_Dynamic_Programming #Udemy_Dynamic_Programming
// #Big_O_Time_O(N)_Space_O(1) #2024_07_03_Time_1_ms_(92.31%)_Space_44.6_MB_(75.65%)
// #Big_O_Time_O(N)_Space_O(1) #2024_11_15_Time_1_ms_(92.74%)_Space_45_MB_(23.41%)

public class Solution {
public int maxProduct(int[] nums) {
int currentMaxProd = nums[0];
int currentMinProd = nums[0];
int overAllMaxProd = nums[0];
for (int i = 1; i < nums.length; i++) {
if (nums[i] < 0) {
int temp = currentMaxProd;
currentMaxProd = currentMinProd;
currentMinProd = temp;
int overAllMaxProd = Integer.MIN_VALUE;
int n = nums.length;
int start = 1;
int end = 1;
for (int i = 0; i < n; i++) {
if (start == 0) {
start = 1;
}
currentMaxProd = Math.max(nums[i], nums[i] * currentMaxProd);
currentMinProd = Math.min(nums[i], nums[i] * currentMinProd);
overAllMaxProd = Math.max(overAllMaxProd, currentMaxProd);
if (end == 0) {
end = 1;
}
start = start * nums[i];
end = end * nums[n - i - 1];
overAllMaxProd = Math.max(overAllMaxProd, Math.max(start, end));
}
return overAllMaxProd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_II_Day_2_Binary_Search
// #Binary_Search_I_Day_12 #Udemy_Binary_Search #Big_O_Time_O(log_N)_Space_O(log_N)
// #2022_06_25_Time_0_ms_(100.00%)_Space_43.3_MB_(6.36%)
// #2024_11_15_Time_0_ms_(100.00%)_Space_42.1_MB_(33.31%)

public class Solution {
private int findMinUtil(int[] nums, int l, int r) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/g0101_0200/s0155_min_stack/MinStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Stack #Design
// #Data_Structure_II_Day_14_Stack_Queue #Programming_Skills_II_Day_18 #Level_2_Day_16_Design
// #Udemy_Design #Big_O_Time_O(1)_Space_O(N) #2022_06_25_Time_3_ms_(100.00%)_Space_44.3_MB_(85.39%)
// #Udemy_Design #Big_O_Time_O(1)_Space_O(N) #2024_11_15_Time_4_ms_(96.54%)_Space_44.5_MB_(84.54%)

public class MinStack {
private static class Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List
// #Data_Structure_II_Day_11_Linked_List #Udemy_Linked_List #Big_O_Time_O(M+N)_Space_O(1)
// #2022_06_25_Time_1_ms_(99.68%)_Space_55.1_MB_(63.42%)
// #2024_11_15_Time_1_ms_(99.92%)_Space_48.4_MB_(68.45%)

import com_github_leetcode.ListNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Sorting #Counting
// #Divide_and_Conquer #Data_Structure_II_Day_1_Array #Udemy_Famous_Algorithm
// #Big_O_Time_O(n)_Space_O(1) #2022_06_25_Time_1_ms_(100.00%)_Space_45.5_MB_(97.51%)
// #Big_O_Time_O(n)_Space_O(1) #2024_11_15_Time_1_ms_(99.89%)_Space_52.8_MB_(64.33%)

public class Solution {
public int majorityElement(int[] arr) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/g0101_0200/s0189_rotate_array/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Two_Pointers
// #Algorithm_I_Day_2_Two_Pointers #Udemy_Arrays #Big_O_Time_O(n)_Space_O(1)
// #2022_06_27_Time_0_ms_(100.00%)_Space_58_MB_(96.22%)
// #2024_11_15_Time_0_ms_(100.00%)_Space_57.7_MB_(14.36%)

public class Solution {
private void reverse(int[] nums, int l, int r) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/g0101_0200/s0198_house_robber/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
// #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_3
// #Level_2_Day_12_Dynamic_Programming #Udemy_Dynamic_Programming #Big_O_Time_O(n)_Space_O(n)
// #2022_06_28_Time_0_ms_(100.00%)_Space_39.9_MB_(85.30%)
// #2024_11_15_Time_0_ms_(100.00%)_Space_40.7_MB_(77.55%)

public class Solution {
public int rob(int[] nums) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// #Breadth_First_Search #Matrix #Union_Find
// #Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search
// #Graph_Theory_I_Day_1_Matrix_Related_Problems #Level_1_Day_9_Graph/BFS/DFS #Udemy_Graph
// #Big_O_Time_O(M*N)_Space_O(M*N) #2022_06_28_Time_3_ms_(97.76%)_Space_57.5_MB_(41.23%)
// #Big_O_Time_O(M*N)_Space_O(M*N) #2024_11_15_Time_3_ms_(87.24%)_Space_49.6_MB_(39.89%)

public class Solution {
public int numIslands(char[][] grid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion
// #Data_Structure_I_Day_8_Linked_List #Algorithm_I_Day_10_Recursion_Backtracking
// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(1)
// #2022_06_28_Time_0_ms_(100.00%)_Space_43.9_MB_(7.98%)
// #2024_11_15_Time_0_ms_(100.00%)_Space_42.5_MB_(41.63%)

import com_github_leetcode.ListNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search
// #Breadth_First_Search #Graph #Topological_Sort #Big_O_Time_O(N)_Space_O(N)
// #2022_06_28_Time_3_ms_(97.58%)_Space_48.2_MB_(49.51%)
// #2024_11_15_Time_3_ms_(99.99%)_Space_44.8_MB_(88.52%)

import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Design #Trie
// #Level_2_Day_16_Design #Udemy_Trie_and_Heap
// #Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N)
// #2022_06_28_Time_34_ms_(99.90%)_Space_51_MB_(94.92%)
// #2024_11_15_Time_32_ms_(95.05%)_Space_54.9_MB_(91.16%)

@SuppressWarnings("java:S1104")
public class Trie {
Expand Down
Loading