File tree 27 files changed +152
-140
lines changed
s0104_maximum_depth_of_binary_tree
s0105_construct_binary_tree_from_preorder_and_inorder_traversal
s0114_flatten_binary_tree_to_linked_list
s0121_best_time_to_buy_and_sell_stock
s0124_binary_tree_maximum_path_sum
s0128_longest_consecutive_sequence
s0131_palindrome_partitioning
s0138_copy_list_with_random_pointer
s0142_linked_list_cycle_ii
s0152_maximum_product_subarray
s0153_find_minimum_in_rotated_sorted_array
s0160_intersection_of_two_linked_lists
s0206_reverse_linked_list
s0208_implement_trie_prefix_tree
s0215_kth_largest_element_in_an_array
27 files changed +152
-140
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 2
2
// #Tree #Binary_Tree #Data_Structure_I_Day_11_Tree
3
3
// #Programming_Skills_I_Day_10_Linked_List_and_Tree #Udemy_Tree_Stack_Queue
4
4
// #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(H)
5
- // #2023_10_04_Time_51_ms_(97.14%)_Space_46.1_MB_(68.29 %)
5
+ // #2025_03_26_Time_0_ms_(100.00%)_Space_59.10_MB_(43.48 %)
6
6
7
7
import { TreeNode } from '../../com_github_leetcode/treenode'
8
8
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Tree #Binary_Tree
2
2
// #Divide_and_Conquer #Data_Structure_II_Day_15_Tree #Top_Interview_150_Binary_Tree_General
3
- // #Big_O_Time_O(N)_Space_O(N) #2023_10_04_Time_65_ms_(96.47%)_Space_45.9_MB_(80.00 %)
3
+ // #Big_O_Time_O(N)_Space_O(N) #2025_03_26_Time_2_ms_(93.38%)_Space_60.17_MB_(76.57 %)
4
4
5
5
import { TreeNode } from '../../com_github_leetcode/treenode'
6
6
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Stack #Linked_List
2
2
// #Udemy_Linked_List #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(N)
3
- // #2023_10_04_Time_55_ms_(90.66%)_Space_45.8_MB_(12.11 %)
3
+ // #2025_03_26_Time_0_ms_(100.00%)_Space_58.93_MB_(15.60 %)
4
4
5
5
import { TreeNode } from '../../com_github_leetcode/treenode'
6
6
Original file line number Diff line number Diff line change 1
1
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
2
2
// #Data_Structure_I_Day_3_Array #Dynamic_Programming_I_Day_7 #Level_1_Day_5_Greedy #Udemy_Arrays
3
3
// #Top_Interview_150_Array/String #Big_O_Time_O(N)_Space_O(1)
4
- // #2023_10_05_Time_56_ms_(99.56%)_Space_52.3_MB_(13.22 %)
4
+ // #2025_03_26_Time_1_ms_(96.44%)_Space_65.83_MB_(26.02 %)
5
5
6
6
function maxProfit ( prices : number [ ] ) : number {
7
7
let buyPrice = prices [ 0 ]
Original file line number Diff line number Diff line change 1
1
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Depth_First_Search
2
2
// #Tree #Binary_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_General
3
- // #Big_O_Time_O(N)_Space_O(N) #2023_10_05_Time_61_ms_(96.73%)_Space_51.2_MB_(97.45 %)
3
+ // #Big_O_Time_O(N)_Space_O(N) #2025_03_26_Time_2_ms_(71.11%)_Space_65.59_MB_(42.96 %)
4
4
5
5
import { TreeNode } from '../../com_github_leetcode/treenode'
6
6
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Union_Find
2
2
// #Top_Interview_150_Hashmap #Big_O_Time_O(N_log_N)_Space_O(1)
3
- // #2023_10_05_Time_92_ms_(93.69%)_Space_64_MB_(30.13 %)
3
+ // #2025_03_26_Time_34_ms_(90.07%)_Space_82.70_MB_(18.54 %)
4
4
5
5
function longestConsecutive ( nums : number [ ] ) : number {
6
- const set = new Set ( nums )
7
- let max = 0
8
- for ( const num of nums ) {
9
- if ( set . has ( num + 1 ) ) continue
10
- let counter = 1 ,
11
- current = num
12
- while ( set . has ( -- current ) ) counter ++
13
- max = Math . max ( counter , max )
6
+ let sset = new Set ( nums )
7
+ let maxLen = 0
8
+ for ( let num of sset ) {
9
+ // check its start of the sequence
10
+ if ( ! sset . has ( num - 1 ) ) {
11
+ let len = 0 ;
12
+ while ( sset . has ( num + len ) ) {
13
+ len += 1
14
+ }
15
+ maxLen = Math . max ( maxLen , len )
16
+ }
14
17
}
15
- return max
18
+ return maxLen
16
19
}
17
20
18
21
export { longestConsecutive }
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming
2
2
// #Backtracking #Big_O_Time_O(N*2^N)_Space_O(2^N*N)
3
- // #2023_10_05_Time_203_ms_(99.22%)_Space_81.9_MB_(42.19 %)
3
+ // #2025_03_26_Time_13_ms_(94.96%)_Space_82.19_MB_(40.76 %)
4
4
5
5
function partition ( s : string ) : string [ ] [ ] {
6
6
const ans : string [ ] [ ] = [ ]
Original file line number Diff line number Diff line change 1
1
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Bit_Manipulation
2
2
// #Data_Structure_II_Day_1_Array #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Integers
3
3
// #Top_Interview_150_Bit_Manipulation #Big_O_Time_O(N)_Space_O(1)
4
- // #2023_10_05_Time_56_ms_(85.48%)_Space_45.6_MB_(63.32 %)
4
+ // #2025_03_26_Time_1_ms_(78.27%)_Space_58.44_MB_(41.08 %)
5
5
6
6
function singleNumber ( nums : number [ ] ) : number {
7
7
let ans = 0
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Linked_List
2
2
// #Programming_Skills_II_Day_14 #Udemy_Linked_List #Top_Interview_150_Linked_List
3
- // #Big_O_Time_O(N)_Space_O(N) #2023_10_06_Time_52_ms_(88.27%)_Space_44.7_MB_(72.42 %)
3
+ // #Big_O_Time_O(N)_Space_O(N) #2025_03_26_Time_49_ms_(72.42%)_Space_55.82_MB_(59.25 %)
4
4
5
5
import { Node } from '../../com_github_leetcode/node'
6
6
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table
2
2
// #Dynamic_Programming #Trie #Memoization #Algorithm_II_Day_15_Dynamic_Programming
3
3
// #Dynamic_Programming_I_Day_9 #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP
4
- // #Big_O_Time_O(M+max*N)_Space_O(M+N+max) #2023_10_06_Time_56_ms_(88.44%)_Space_44.1_MB_(93.39 %)
4
+ // #Big_O_Time_O(M+max*N)_Space_O(M+N+max) #2025_03_26_Time_4_ms_(76.41%)_Space_58.68_MB_(22.70 %)
5
5
6
6
function wordBreak ( s : string , wordDict : string [ ] ) : boolean {
7
7
const dp : boolean [ ] = [ ]
Original file line number Diff line number Diff line change 1
1
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List
2
2
// #Data_Structure_I_Day_7_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List
3
- // #Big_O_Time_O(N)_Space_O(1) #2023_10_06_Time_59_ms_(93 .37%)_Space_45.2_MB_(76.28 %)
3
+ // #Big_O_Time_O(N)_Space_O(1) #2025_03_26_Time_47_ms_(89 .37%)_Space_58.35_MB_(35.02 %)
4
4
5
5
import { ListNode } from '../../com_github_leetcode/listnode'
6
6
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Hash_Table #Two_Pointers #Linked_List
2
2
// #Data_Structure_II_Day_10_Linked_List #Level_1_Day_4_Linked_List #Udemy_Linked_List
3
- // #Big_O_Time_O(N)_Space_O(1) #2023_10_06_Time_59_ms_(94.39%)_Space_45.5_MB_(60.71 %)
3
+ // #Big_O_Time_O(N)_Space_O(1) #2025_03_26_Time_51_ms_(76.99%)_Space_59.02_MB_(13.39 %)
4
4
5
5
import { ListNode } from '../../com_github_leetcode/listnode'
6
6
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Design #Linked_List
2
2
// #Doubly_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List
3
- // #Big_O_Time_O(1)_Space_O(capacity) #2023_10_06_Time_473_ms_(94.72%)_Space_125.1_MB_(69.62 %)
3
+ // #Big_O_Time_O(1)_Space_O(capacity) #2025_03_26_Time_97_ms_(81.52%)_Space_108.56_MB_(48.32 %)
4
4
5
5
interface ICacheNode {
6
6
key : number
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Sorting #Two_Pointers #Linked_List
2
2
// #Divide_and_Conquer #Merge_Sort #Level_2_Day_4_Linked_List #Top_Interview_150_Divide_and_Conquer
3
- // #Big_O_Time_O(log(N))_Space_O(log(N)) #2023_10_08_Time_141_ms_(97.14%)_Space_71.9_MB_(47.35 %)
3
+ // #Big_O_Time_O(log(N))_Space_O(log(N)) #2025_03_26_Time_36_ms_(44.94%)_Space_86.58_MB_(5.99 %)
4
4
5
5
import { ListNode } from '../../com_github_leetcode/listnode'
6
6
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
2
2
// #Dynamic_Programming_I_Day_6 #Level_2_Day_13_Dynamic_Programming #Udemy_Dynamic_Programming
3
- // #Big_O_Time_O(N)_Space_O(1) #2023_10_08_Time_53_ms_(87.50%)_Space_44.6_MB_(63.86 %)
3
+ // #Big_O_Time_O(N)_Space_O(1) #2025_03_26_Time_0_ms_(100.00%)_Space_58.34_MB_(23.08 %)
4
4
5
5
function maxProduct ( nums : number [ ] ) : number {
6
6
let cMin = 1
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_II_Day_2_Binary_Search
2
2
// #Binary_Search_I_Day_12 #Udemy_Binary_Search #Top_Interview_150_Binary_Search
3
- // #Big_O_Time_O(log_N)_Space_O(log_N) #2023_10_08_Time_42_ms_(98.87%)_Space_42.9_MB_(84.75 %)
3
+ // #Big_O_Time_O(log_N)_Space_O(log_N) #2025_03_26_Time_0_ms_(100.00%)_Space_55.42_MB_(40.88 %)
4
4
5
5
function findMin ( nums : number [ ] ) : number {
6
6
return Math . min ( ...nums )
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Stack #Design
2
2
// #Data_Structure_II_Day_14_Stack_Queue #Programming_Skills_II_Day_18 #Level_2_Day_16_Design
3
3
// #Udemy_Design #Top_Interview_150_Stack #Big_O_Time_O(1)_Space_O(N)
4
- // #2023_10_08_Time_84_ms_(92.72%)_Space_51.8_MB_(30.46 %)
4
+ // #2025_03_26_Time_5_ms_(99.10%)_Space_65.70_MB_(50.04 %)
5
5
6
6
class MinStack {
7
7
stack : number [ ]
Original file line number Diff line number Diff line change 1
1
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List
2
2
// #Data_Structure_II_Day_11_Linked_List #Udemy_Linked_List #Big_O_Time_O(M+N)_Space_O(1)
3
- // #2023_10_08_Time_67_ms_(93.58%)_Space_50.8_MB_(40.54 %)
3
+ // #2025_03_26_Time_65_ms_(72.36%)_Space_63.62_MB_(41.12 %)
4
4
5
5
import { ListNode } from '../../com_github_leetcode/listnode'
6
6
Original file line number Diff line number Diff line change 1
1
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Sorting #Counting
2
2
// #Divide_and_Conquer #Data_Structure_II_Day_1_Array #Udemy_Famous_Algorithm
3
3
// #Top_Interview_150_Array/String #Big_O_Time_O(n)_Space_O(1)
4
- // #2023_10_09_Time_50_ms_(96.16%)_Space_46.1_MB_(46.90 %)
4
+ // #2025_03_26_Time_0_ms_(100.00%)_Space_60.31_MB_(17.26 %)
5
5
6
6
function majorityElement ( arr : number [ ] ) : number {
7
7
let count = 1
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Two_Pointers
2
2
// #Algorithm_I_Day_2_Two_Pointers #Udemy_Arrays #Top_Interview_150_Array/String
3
- // #Big_O_Time_O(n)_Space_O(1) #2023_10_09_Time_75_ms_(97.25%)_Space_52_MB_(63 .34%)
3
+ // #Big_O_Time_O(n)_Space_O(1) #2025_03_26_Time_1_ms_(86.17%)_Space_64.71_MB_(43 .34%)
4
4
5
5
/*
6
6
Do not return anything, modify nums in-place instead.
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
2
2
// #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_3
3
3
// #Level_2_Day_12_Dynamic_Programming #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP
4
- // #Big_O_Time_O(n)_Space_O(n) #2023_10_09_Time_51_ms_(77.29%)_Space_42.7_MB_(62.58 %)
4
+ // #Big_O_Time_O(n)_Space_O(n) #2025_03_26_Time_0_ms_(100.00%)_Space_55.74_MB_(28.06 %)
5
5
6
6
function rob ( nums : number [ ] ) : number {
7
7
const n = nums . length
Original file line number Diff line number Diff line change 3
3
// #Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search
4
4
// #Graph_Theory_I_Day_1_Matrix_Related_Problems #Level_1_Day_9_Graph/BFS/DFS #Udemy_Graph
5
5
// #Top_Interview_150_Graph_General #Big_O_Time_O(M*N)_Space_O(M*N)
6
- // #2023_10_09_Time_61_ms_(96.71%)_Space_44.5_MB_(99.30 %)
6
+ // #2025_03_26_Time_57_ms_(93.94%)_Space_59.21_MB_(64.22 %)
7
7
8
8
function numIslands ( grid : string [ ] [ ] ) : number {
9
9
let islands = 0
Original file line number Diff line number Diff line change 1
1
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Linked_List #Recursion
2
2
// #Data_Structure_I_Day_8_Linked_List #Algorithm_I_Day_10_Recursion_Backtracking
3
3
// #Level_1_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(1)
4
- // #2023_10_09_Time_51_ms_(92.87%)_Space_44.3_MB_(96.03 %)
4
+ // #2025_03_26_Time_0_ms_(100.00%)_Space_58.92_MB_(16.01 %)
5
5
6
6
import { ListNode } from '../../com_github_leetcode/listnode'
7
7
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search
2
2
// #Breadth_First_Search #Graph #Topological_Sort #Top_Interview_150_Graph_General
3
- // #Big_O_Time_O(N)_Space_O(N) #2023_10_09_Time_68_ms_(70.14%)_Space_47.7_MB_(73.55 %)
3
+ // #Big_O_Time_O(N)_Space_O(N) #2025_03_26_Time_11_ms_(81.08%)_Space_62.76_MB_(51.00 %)
4
4
5
5
const WHITE = 0
6
6
const GRAY = 1
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Design #Trie
2
2
// #Level_2_Day_16_Design #Udemy_Trie_and_Heap #Top_Interview_150_Trie
3
3
// #Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N)
4
- // #2023_10_09_Time_168_ms_(80.99%)_Space_79.5_MB_(14.46 %)
4
+ // #2025_03_26_Time_48_ms_(63.95%)_Space_81.97_MB_(12.22 %)
5
5
6
6
class TrieNode {
7
7
children : TrieNode [ ]
Original file line number Diff line number Diff line change 1
1
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Heap_Priority_Queue
2
2
// #Divide_and_Conquer #Quickselect #Data_Structure_II_Day_20_Heap_Priority_Queue
3
3
// #Top_Interview_150_Heap #Big_O_Time_O(n*log(n))_Space_O(log(n))
4
- // #2023_10_09_Time_148_ms_(54.45%)_Space_51.5_MB_(73.60 %)
4
+ // #2025_03_26_Time_4_ms_(99.64%)_Space_66.28_MB_(62.13 %)
5
5
6
6
function findKthLargest ( nums : number [ ] , k : number ) : number {
7
- nums . sort ( ( prev , next ) => next - prev )
8
- return nums [ k - 1 ]
7
+ const countingLen = 2e4 + 1
8
+ const counting = new Int32Array ( countingLen )
9
+ for ( const num of nums ) {
10
+ counting [ num + 1e4 ] ++ ;
11
+ }
12
+ for ( let i = countingLen - 1 ; i >= 0 ; i -- ) {
13
+ k -= counting [ i ]
14
+ if ( k <= 0 ) {
15
+ return i - 1e4
16
+ }
17
+ }
9
18
}
10
19
11
20
export { findKthLargest }
You can’t perform that action at this time.
0 commit comments