Skip to content

Commit d8321c1

Browse files
committed
Added racket
1 parent 5c2e020 commit d8321c1

File tree

45 files changed

+1259
-10
lines changed

Some content is hidden

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

45 files changed

+1259
-10
lines changed

src/main/racket/g0001_0100/s0001_two_sum/Solution.rkt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table
2-
; #Data_Structure_I_Day_2_Array #Level_1_Day_13_Hashmap #Udemy_Arrays #Big_O_Time_O(n)_Space_O(n)
3-
; #AI_can_be_used_to_solve_the_task #2025_01_28_Time_0_(100.00%)_Space_102.07_(45.83%)
2+
; #Data_Structure_I_Day_2_Array #Level_1_Day_13_Hashmap #Udemy_Arrays #Top_Interview_150_Hashmap
3+
; #Big_O_Time_O(n)_Space_O(n) #AI_can_be_used_to_solve_the_task
4+
; #2025_02_05_Time_0_(100.00%)_Space_102.04_(40.82%)
45

56
(define (two-sum-iter nums target hash index)
67
(cond

src/main/racket/g0001_0100/s0002_add_two_numbers/Solution.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Math #Linked_List #Recursion
22
; #Data_Structure_II_Day_10_Linked_List #Programming_Skills_II_Day_15
3-
; #Big_O_Time_O(max(N,M))_Space_O(max(N,M)) #AI_can_be_used_to_solve_the_task
4-
; #2025_01_28_Time_0_(100.00%)_Space_128.42_(12.50%)
3+
; #Top_Interview_150_Linked_List #Big_O_Time_O(max(N,M))_Space_O(max(N,M))
4+
; #AI_can_be_used_to_solve_the_task #2025_02_05_Time_0_(100.00%)_Space_128.08_(72.73%)
55

66
; Definition for singly-linked list:
77
#|

src/main/racket/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Sliding_Window
22
; #Algorithm_I_Day_6_Sliding_Window #Level_2_Day_14_Sliding_Window/Two_Pointer #Udemy_Strings
3-
; #Big_O_Time_O(n)_Space_O(1) #AI_can_be_used_to_solve_the_task
4-
; #2025_01_28_Time_134_(75.00%)_Space_132.36_(100.00%)
3+
; #Top_Interview_150_Sliding_Window #Big_O_Time_O(n)_Space_O(1) #AI_can_be_used_to_solve_the_task
4+
; #2025_02_06_Time_119_(71.43%)_Space_131.37_(28.57%)
55

66
; Helper function to get the sublist up to 'v' excluded.
77
(define (take-till q v)

src/main/racket/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Binary_Search #Divide_and_Conquer
2-
; #Big_O_Time_O(log(min(N,M)))_Space_O(1) #AI_can_be_used_to_solve_the_task
3-
; #2025_01_28_Time_0_(100.00%)_Space_128.57_(100.00%)
2+
; #Top_Interview_150_Binary_Search #Big_O_Time_O(log(min(N,M)))_Space_O(1)
3+
; #AI_can_be_used_to_solve_the_task #2025_02_06_Time_0_(100.00%)_Space_128.80_(25.00%)
44

55
(define/contract (find-median-sorted-arrays nums1 nums2)
66
(-> (listof exact-integer?) (listof exact-integer?) flonum?)

src/main/racket/g0001_0100/s0005_longest_palindromic_substring/Solution.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming
22
; #Data_Structure_II_Day_9_String #Algorithm_II_Day_14_Dynamic_Programming
3-
; #Dynamic_Programming_I_Day_17 #Udemy_Strings #Big_O_Time_O(n)_Space_O(n)
4-
; #2025_01_28_Time_10_(50.00%)_Space_102.35_(50.00%)
3+
; #Dynamic_Programming_I_Day_17 #Udemy_Strings #Top_Interview_150_Multidimensional_DP
4+
; #Big_O_Time_O(n)_Space_O(n) #2025_02_06_Time_4_(100.00%)_Space_101.40_(85.71%)
55

66
(define (longest-palindrome s)
77
(define (expand-around-center s left right)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
; #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Matrix
2+
; #Dynamic_Programming_I_Day_16 #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP
3+
; #Big_O_Time_O(m*n)_Space_O(m*n) #2025_02_04_Time_92_(100.00%)_Space_133.91_(100.00%)
4+
5+
; dynamic programming helper function
6+
(define (mpsAux grid curpos dpTable ub)
7+
(local
8+
[(define (get grid pos) (list-ref (list-ref grid (car pos)) (cdr pos)))]
9+
(cond
10+
; return start value
11+
[(equal? curpos (cons 0 0)) (car (car grid))]
12+
13+
; handle out of bounds
14+
[(or (< (car curpos) 0) (< (cdr curpos) 0)) +inf.0]
15+
16+
; position appeared before
17+
[(hash-ref dpTable curpos #f) (hash-ref dpTable curpos)]
18+
19+
; inductive case
20+
[else
21+
(let*
22+
(
23+
; go up
24+
[u_val (mpsAux grid (cons (- (car curpos) 1) (cdr curpos)) dpTable ub)]
25+
26+
; go left
27+
[l_val (mpsAux grid (cons (car curpos) (- (cdr curpos) 1)) dpTable ub)]
28+
29+
; compute the current least cost
30+
[cur-least-cost (+ (get grid curpos) (min u_val l_val))]
31+
)
32+
(hash-set! dpTable curpos cur-least-cost)
33+
cur-least-cost
34+
)
35+
]
36+
)
37+
)
38+
)
39+
40+
; the (x . y) position of the grid is the x'th row and y'th column of the grid
41+
(define/contract (min-path-sum grid)
42+
(-> (listof (listof exact-integer?)) exact-integer?)
43+
(local
44+
[(define dpTable (make-hash))]
45+
(let*
46+
(
47+
[curpos (cons (- (length grid) 1) (- (length (car grid)) 1))]
48+
[least-val (mpsAux grid curpos dpTable 200)]
49+
)
50+
(inexact->exact least-val)
51+
)
52+
)
53+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
64\. Minimum Path Sum
2+
3+
Medium
4+
5+
Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
6+
7+
**Note:** You can only move either down or right at any point in time.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2020/11/05/minpath.jpg)
12+
13+
**Input:** grid = [[1,3,1],[1,5,1],[4,2,1]]
14+
15+
**Output:** 7
16+
17+
**Explanation:** Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.
18+
19+
**Example 2:**
20+
21+
**Input:** grid = [[1,2,3],[4,5,6]]
22+
23+
**Output:** 12
24+
25+
**Constraints:**
26+
27+
* `m == grid.length`
28+
* `n == grid[i].length`
29+
* `1 <= m, n <= 200`
30+
* `0 <= grid[i][j] <= 100`
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Math #Memoization
2+
; #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_2
3+
; #Level_1_Day_10_Dynamic_Programming #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP
4+
; #Big_O_Time_O(n)_Space_O(n) #2025_02_04_Time_0_(100.00%)_Space_101.51_(100.00%)
5+
6+
(define (clmHelp n hTable)
7+
(cond
8+
; base cases
9+
((= 1 n) 1)
10+
((= 2 n) 2)
11+
((hash-ref hTable n #f) (hash-ref hTable n))
12+
13+
; inductive case
14+
(else
15+
(let*
16+
; the local variables
17+
(
18+
(a (clmHelp (- n 1) hTable))
19+
(b (clmHelp (- n 2) hTable))
20+
(numPos (+ a b))
21+
)
22+
23+
; the body
24+
(hash-set! hTable n numPos)
25+
numPos
26+
)
27+
)
28+
)
29+
)
30+
31+
(define/contract (climb-stairs n)
32+
(-> exact-integer? exact-integer?)
33+
(local
34+
; local definitions
35+
((define hTable (make-hash)))
36+
37+
; function body
38+
(clmHelp n hTable)
39+
)
40+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
70\. Climbing Stairs
2+
3+
Easy
4+
5+
You are climbing a staircase. It takes `n` steps to reach the top.
6+
7+
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
8+
9+
**Example 1:**
10+
11+
**Input:** n = 2
12+
13+
**Output:** 2
14+
15+
**Explanation:** There are two ways to climb to the top.
16+
17+
1. 1 step + 1 step
18+
19+
2. 2 steps
20+
21+
**Example 2:**
22+
23+
**Input:** n = 3
24+
25+
**Output:** 3
26+
27+
**Explanation:** There are three ways to climb to the top.
28+
29+
1. 1 step + 1 step + 1 step
30+
31+
2. 1 step + 2 steps
32+
33+
3. 2 steps + 1 step
34+
35+
**Constraints:**
36+
37+
* `1 <= n <= 45`
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; #Medium #Top_100_Liked_Questions #String #Dynamic_Programming
2+
; #Algorithm_II_Day_18_Dynamic_Programming #Dynamic_Programming_I_Day_19
3+
; #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP #Big_O_Time_O(n^2)_Space_O(n2)
4+
; #2025_02_04_Time_4_(100.00%)_Space_102.31_(100.00%)
5+
6+
(define/contract (min-distance word1 word2)
7+
(-> string? string? exact-integer?)
8+
(let* ((n1 (string-length word1))
9+
(n2 (string-length word2)))
10+
(if (> n2 n1)
11+
(min-distance word2 word1)
12+
(let ((dp (make-vector (+ n2 1) 0)))
13+
(for ([j (in-range (+ n2 1))])
14+
(vector-set! dp j j))
15+
(for ([i (in-range 1 (+ n1 1))])
16+
(let ((pre (vector-ref dp 0)))
17+
(vector-set! dp 0 i)
18+
(for ([j (in-range 1 (+ n2 1))])
19+
(let* ((tmp (vector-ref dp j))
20+
(cost (if (char=? (string-ref word1 (- i 1)) (string-ref word2 (- j 1)))
21+
pre
22+
(+ 1 (min pre (vector-ref dp j) (vector-ref dp (- j 1)))))))
23+
(vector-set! dp j cost)
24+
(set! pre tmp)))))
25+
(vector-ref dp n2)))))

0 commit comments

Comments
 (0)