Skip to content

Commit 9f7d77c

Browse files
authored
Added tasks 67-77
1 parent 6414fe3 commit 9f7d77c

File tree

16 files changed

+416
-0
lines changed

16 files changed

+416
-0
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
5050

5151
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
5252
|-|-|-|-|-|-
53+
| 0069 |[Sqrt(x)](src/main/ts/g0001_0100/s0069_sqrtx/solution.ts)| Hard | Array, String, Simulation | 0 | 100.00
5354

5455
#### Day 5
5556

@@ -418,6 +419,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
418419

419420
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
420421
|-|-|-|-|-|-
422+
| 0067 |[Add Binary](src/main/ts/g0001_0100/s0067_add_binary/solution.ts)| Easy | String, Math, Bit_Manipulation, Simulation | 0 | 100.00
421423

422424
#### Day 6
423425

@@ -1018,6 +1020,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10181020
| 0014 |[Longest Common Prefix](src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String | 0 | 100.00
10191021
| 0006 |[Zigzag Conversion](src/main/ts/g0001_0100/s0006_zigzag_conversion/solution.ts)| Medium | String | 2 | 99.08
10201022
| 0028 |[Implement strStr()](src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00
1023+
| 0068 |[Text Justification](src/main/ts/g0001_0100/s0068_text_justification/solution.ts)| Hard | Array, String, Simulation | 0 | 100.00
10211024

10221025
#### Top Interview 150 Two Pointers
10231026

@@ -1063,6 +1066,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10631066
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10641067
|-|-|-|-|-|-
10651068
| 0020 |[Valid Parentheses](src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 1 | 86.85
1069+
| 0071 |[Simplify Path](src/main/ts/g0001_0100/s0071_simplify_path/solution.ts)| Medium | String, Stack | 0 | 100.00
10661070
| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 5 | 99.10
10671071

10681072
#### Top Interview 150 Linked List
@@ -1126,6 +1130,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
11261130
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11271131
|-|-|-|-|-|-
11281132
| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
1133+
| 0077 |[Combinations](src/main/ts/g0001_0100/s0077_combinations/solution.ts)| Medium | Backtracking | 46 | 96.14
11291134
| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 84.44
11301135
| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 98.17
11311136
| 0052 |[N-Queens II](src/main/ts/g0001_0100/s0052_n_queens_ii/solution.ts)| Hard | Backtracking | 1 | 96.89
@@ -1167,6 +1172,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
11671172

11681173
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11691174
|-|-|-|-|-|-
1175+
| 0067 |[Add Binary](src/main/ts/g0001_0100/s0067_add_binary/solution.ts)| Easy | String, Math, Bit_Manipulation, Simulation | 0 | 100.00
11701176
| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 78.27
11711177

11721178
#### Top Interview 150 Math
@@ -1175,6 +1181,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
11751181
|-|-|-|-|-|-
11761182
| 0009 |[Palindrome Number](src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts)| Easy | Math | 3 | 99.14
11771183
| 0066 |[Plus One](src/main/ts/g0001_0100/s0066_plus_one/solution.ts)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00
1184+
| 0069 |[Sqrt(x)](src/main/ts/g0001_0100/s0069_sqrtx/solution.ts)| Hard | Array, String, Simulation | 0 | 100.00
11781185
| 0050 |[Pow(x, n)](src/main/ts/g0001_0100/s0050_powx_n/solution.ts)| Medium | Top_Interview_Questions, Math, Recursion | 0 | 100.00
11791186

11801187
#### Top Interview 150 1D DP
@@ -1477,6 +1484,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
14771484

14781485
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
14791486
|-|-|-|-|-|-
1487+
| 0077 |[Combinations](src/main/ts/g0001_0100/s0077_combinations/solution.ts)| Medium | Backtracking | 46 | 96.14
14801488
| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 1 | 84.44
14811489

14821490
#### Day 12 Dynamic Programming
@@ -1690,12 +1698,17 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
16901698
| 0084 |[Largest Rectangle in Histogram](src/main/ts/g0001_0100/s0084_largest_rectangle_in_histogram/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n_log_n)_Space_O(log_n) | 15 | 72.81
16911699
| 0079 |[Word Search](src/main/ts/g0001_0100/s0079_word_search/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Top_Interview_150_Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 243 | 85.30
16921700
| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Algorithm_II_Day_9_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 0 | 100.00
1701+
| 0077 |[Combinations](src/main/ts/g0001_0100/s0077_combinations/solution.ts)| Medium | Backtracking, Algorithm_I_Day_11_Recursion_Backtracking, Top_Interview_150_Backtracking | 46 | 96.14
16931702
| 0076 |[Minimum Window Substring](src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Top_Interview_150_Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 20 | 90.35
16941703
| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_2_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
16951704
| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Data_Structure_I_Day_5_Array, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_8, Level_2_Day_8_Binary_Search, Udemy_2D_Arrays/Matrix, Top_Interview_150_Binary_Search, Big_O_Time_O(endRow+endCol)_Space_O(1) | 0 | 100.00
16961705
| 0073 |[Set Matrix Zeroes](src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Udemy_2D_Arrays/Matrix, Top_Interview_150_Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 4 | 50.63
16971706
| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance/solution.ts)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Top_Interview_150_Multidimensional_DP, Big_O_Time_O(n^2)_Space_O(n2) | 6 | 93.83
1707+
| 0071 |[Simplify Path](src/main/ts/g0001_0100/s0071_simplify_path/solution.ts)| Medium | String, Stack, Top_Interview_150_Stack | 0 | 100.00
16981708
| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_2, Level_1_Day_10_Dynamic_Programming, Udemy_Dynamic_Programming, Top_Interview_150_1D_DP, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1709+
| 0069 |[Sqrt(x)](src/main/ts/g0001_0100/s0069_sqrtx/solution.ts)| Hard | Array, String, Simulation, Top_Interview_150_Array/String | 0 | 100.00
1710+
| 0068 |[Text Justification](src/main/ts/g0001_0100/s0068_text_justification/solution.ts)| Hard | Array, String, Simulation, Top_Interview_150_Array/String | 0 | 100.00
1711+
| 0067 |[Add Binary](src/main/ts/g0001_0100/s0067_add_binary/solution.ts)| Easy | String, Math, Bit_Manipulation, Simulation, Programming_Skills_II_Day_5, Top_Interview_150_Bit_Manipulation | 0 | 100.00
16991712
| 0066 |[Plus One](src/main/ts/g0001_0100/s0066_plus_one/solution.ts)| Easy | Top_Interview_Questions, Array, Math, Programming_Skills_II_Day_3, Udemy_Arrays, Top_Interview_150_Math | 0 | 100.00
17001713
| 0064 |[Minimum Path Sum](src/main/ts/g0001_0100/s0064_minimum_path_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Udemy_Dynamic_Programming, Top_Interview_150_Multidimensional_DP, Big_O_Time_O(m\*n)_Space_O(m\*n) | 4 | 70.73
17011714
| 0063 |[Unique Paths II](src/main/ts/g0001_0100/s0063_unique_paths_ii/solution.ts)| Medium | Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_15, Top_Interview_150_Multidimensional_DP | 0 | 100.00
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
67\. Add Binary
2+
3+
Easy
4+
5+
Given two binary strings `a` and `b`, return _their sum as a binary string_.
6+
7+
**Example 1:**
8+
9+
**Input:** a = "11", b = "1"
10+
11+
**Output:** "100"
12+
13+
**Example 2:**
14+
15+
**Input:** a = "1010", b = "1011"
16+
17+
**Output:** "10101"
18+
19+
**Constraints:**
20+
21+
* <code>1 <= a.length, b.length <= 10<sup>4</sup></code>
22+
* `a` and `b` consist only of `'0'` or `'1'` characters.
23+
* Each string does not contain leading zeros except for the zero itself.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// #Easy #String #Math #Bit_Manipulation #Simulation #Programming_Skills_II_Day_5
2+
// #Top_Interview_150_Bit_Manipulation #2025_04_05_Time_0_ms_(100.00%)_Space_58.14_MB_(39.81%)
3+
4+
function addBinary(a: string, b: string): string {
5+
const aArray = a.split('')
6+
const bArray = b.split('')
7+
let sb: string[] = []
8+
let i = aArray.length - 1
9+
let j = bArray.length - 1
10+
let carry = 0
11+
while (i >= 0 || j >= 0) {
12+
const digitA = i >= 0 ? parseInt(aArray[i]) : 0
13+
const digitB = j >= 0 ? parseInt(bArray[j]) : 0
14+
const sum = digitA + digitB + carry
15+
sb.push((sum % 2).toString())
16+
carry = Math.floor(sum / 2)
17+
i--
18+
j--
19+
}
20+
if (carry !== 0) {
21+
sb.push(carry.toString())
22+
}
23+
return sb.reverse().join('')
24+
}
25+
26+
export { addBinary }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
68\. Text Justification
2+
3+
Hard
4+
5+
Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
6+
7+
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that each line has exactly `maxWidth` characters.
8+
9+
Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.
10+
11+
For the last line of text, it should be left-justified and no extra space is inserted between words.
12+
13+
**Note:**
14+
15+
* A word is defined as a character sequence consisting of non-space characters only.
16+
* Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
17+
* The input array `words` contains at least one word.
18+
19+
**Example 1:**
20+
21+
**Input:** words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16
22+
23+
**Output:** [ "This is an", "example of text", "justification. " ]
24+
25+
**Example 2:**
26+
27+
**Input:** words = ["What","must","be","acknowledgment","shall","be"], maxWidth = 16
28+
29+
**Output:** [ "What must be", "acknowledgment ", "shall be " ]
30+
31+
**Explanation:** Note that the last line is "shall be " instead of "shall be", because the last line must be left-justified instead of fully-justified. Note that the second line is also left-justified becase it contains only one word.
32+
33+
**Example 3:**
34+
35+
**Input:** words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"], maxWidth = 20
36+
37+
**Output:** [ "Science is what we", "understand well", "enough to explain to", "a computer. Art is", "everything else we", "do " ]
38+
39+
**Constraints:**
40+
41+
* `1 <= words.length <= 300`
42+
* `1 <= words[i].length <= 20`
43+
* `words[i]` consists of only English letters and symbols.
44+
* `1 <= maxWidth <= 100`
45+
* `words[i].length <= maxWidth`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// #Hard #Array #String #Simulation #Top_Interview_150_Array/String
2+
// #2025_04_05_Time_0_ms_(100.00%)_Space_55.70_MB_(38.14%)
3+
4+
function fullJustify(words: string[], maxWidth: number): string[] {
5+
const output: string[] = []
6+
let sb: string[] = []
7+
let lineTotal = 0
8+
let numWordsOnLine = 0
9+
let startWord = 0
10+
for (let i = 0; i < words.length - 1; i++) {
11+
lineTotal += words[i].length
12+
numWordsOnLine++
13+
if (lineTotal + numWordsOnLine + words[i + 1].length > maxWidth) {
14+
sb = []
15+
if (numWordsOnLine === 1) {
16+
sb.push(words[i])
17+
while (lineTotal++ < maxWidth) {
18+
sb.push(' ')
19+
}
20+
} else {
21+
const spaces = Math.floor((maxWidth - lineTotal) / (numWordsOnLine - 1))
22+
let extraSp = (maxWidth - lineTotal) % (numWordsOnLine - 1)
23+
24+
for (let j = startWord; j < startWord + numWordsOnLine - 1; j++) {
25+
sb.push(words[j])
26+
sb.push(' '.repeat(spaces + (extraSp-- > 0 ? 1 : 0)))
27+
}
28+
sb.push(words[startWord + numWordsOnLine - 1])
29+
}
30+
output.push(sb.join(''))
31+
startWord = i + 1
32+
numWordsOnLine = lineTotal = 0
33+
}
34+
}
35+
36+
// Handle last line
37+
sb = []
38+
lineTotal = 0
39+
for (let i = startWord; i < words.length; i++) {
40+
lineTotal += words[i].length
41+
sb.push(words[i])
42+
if (lineTotal < maxWidth) {
43+
sb.push(' ')
44+
lineTotal++
45+
}
46+
}
47+
while (lineTotal < maxWidth) {
48+
sb.push(' ')
49+
lineTotal++
50+
}
51+
output.push(sb.join(''))
52+
53+
return output
54+
}
55+
56+
export { fullJustify }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
69\. Sqrt(x)
2+
3+
Easy
4+
5+
Given a non-negative integer `x`, compute and return _the square root of_ `x`.
6+
7+
Since the return type is an integer, the decimal digits are **truncated**, and only **the integer part** of the result is returned.
8+
9+
**Note:** You are not allowed to use any built-in exponent function or operator, such as `pow(x, 0.5)` or `x ** 0.5`.
10+
11+
**Example 1:**
12+
13+
**Input:** x = 4
14+
15+
**Output:** 2
16+
17+
**Example 2:**
18+
19+
**Input:** x = 8
20+
21+
**Output:** 2
22+
23+
**Explanation:** The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
24+
25+
**Constraints:**
26+
27+
* <code>0 <= x <= 2<sup>31</sup> - 1</code>
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// #Hard #Array #String #Simulation #Top_Interview_150_Array/String
2+
// #2025_04_05_Time_0_ms_(100.00%)_Space_55.70_MB_(38.14%)
3+
4+
function mySqrt(x: number): number {
5+
let low = 1
6+
let high = x
7+
let lowest = 0
8+
while (low <= high) {
9+
const mid = Math.floor((low + high) / 2)
10+
const pow = mid * mid
11+
if(pow > x) {
12+
high = mid - 1
13+
} else if(pow < x) {
14+
low = mid + 1
15+
lowest = mid
16+
} else {
17+
return mid
18+
}
19+
}
20+
return lowest
21+
}
22+
23+
export { mySqrt }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
71\. Simplify Path
2+
3+
Medium
4+
5+
Given a string `path`, which is an **absolute path** (starting with a slash `'/'`) to a file or directory in a Unix-style file system, convert it to the simplified **canonical path**.
6+
7+
In a Unix-style file system, a period `'.'` refers to the current directory, a double period `'..'` refers to the directory up a level, and any multiple consecutive slashes (i.e. `'//'`) are treated as a single slash `'/'`. For this problem, any other format of periods such as `'...'` are treated as file/directory names.
8+
9+
The **canonical path** should have the following format:
10+
11+
* The path starts with a single slash `'/'`.
12+
* Any two directories are separated by a single slash `'/'`.
13+
* The path does not end with a trailing `'/'`.
14+
* The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period `'.'` or double period `'..'`)
15+
16+
Return _the simplified **canonical path**_.
17+
18+
**Example 1:**
19+
20+
**Input:** path = "/home/"
21+
22+
**Output:** "/home"
23+
24+
**Explanation:** Note that there is no trailing slash after the last directory name.
25+
26+
**Example 2:**
27+
28+
**Input:** path = "/../"
29+
30+
**Output:** "/"
31+
32+
**Explanation:** Going one level up from the root directory is a no-op, as the root level is the highest level you can go.
33+
34+
**Example 3:**
35+
36+
**Input:** path = "/home//foo/"
37+
38+
**Output:** "/home/foo"
39+
40+
**Explanation:** In the canonical path, multiple consecutive slashes are replaced by a single one.
41+
42+
**Example 4:**
43+
44+
**Input:** path = "/a/./b/../../c/"
45+
46+
**Output:** "/c"
47+
48+
**Constraints:**
49+
50+
* `1 <= path.length <= 3000`
51+
* `path` consists of English letters, digits, period `'.'`, slash `'/'` or `'_'`.
52+
* `path` is a valid absolute Unix path.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// #Medium #String #Stack #Top_Interview_150_Stack
2+
// #2025_04_05_Time_0_ms_(100.00%)_Space_58.31_MB_(30.21%)
3+
4+
function simplifyPath(path: string): string {
5+
const stack = []
6+
const mod = path.split('/').filter((element) => element.length)
7+
for (const element of mod) {
8+
if (element === '..') {
9+
stack.pop()
10+
} else if (element === '.') {
11+
continue
12+
} else {
13+
stack.push(element)
14+
}
15+
}
16+
return '/'.concat(stack.join('/'))
17+
}
18+
19+
export { simplifyPath }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
77\. Combinations
2+
3+
Medium
4+
5+
Given two integers `n` and `k`, return _all possible combinations of_ `k` _numbers out of the range_ `[1, n]`.
6+
7+
You may return the answer in **any order**.
8+
9+
**Example 1:**
10+
11+
**Input:** n = 4, k = 2
12+
13+
**Output:** [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ]
14+
15+
**Example 2:**
16+
17+
**Input:** n = 1, k = 1
18+
19+
**Output:** [[1]]
20+
21+
**Constraints:**
22+
23+
* `1 <= n <= 20`
24+
* `1 <= k <= n`

0 commit comments

Comments
 (0)