Skip to content

Commit 808d5f8

Browse files
authored
Added tasks 68-82
1 parent d9907b1 commit 808d5f8

File tree

16 files changed

+498
-0
lines changed

16 files changed

+498
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
401401
| 0283 |[Move Zeroes](src/main/python/g0201_0300/s0283_move_zeroes/Solution0283.py)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, LeetCode_75_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 3 | 80.05
402402
| 0001 |[Two Sum](src/main/python/g0001_0100/s0001_two_sum/Solution0001.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 0 | 100.00
403403
| 0058 |[Length of Last Word](src/main/python/g0001_0100/s0058_length_of_last_word/Solution0058.py)| Easy | String | 0 | 100.00
404+
| 0080 |[Remove Duplicates from Sorted Array II](src/main/python/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution0080.py)| Medium | Array, Two_Pointers | 73 | 96.40
404405
| 0189 |[Rotate Array](src/main/python/g0101_0200/s0189_rotate_array/Solution0189.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 3 | 74.65
405406
| 0055 |[Jump Game](src/main/python/g0001_0100/s0055_jump_game/Solution0055.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 12 | 85.38
406407
| 0075 |[Sort Colors](src/main/python/g0001_0100/s0075_sort_colors/Solution0075.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
@@ -525,6 +526,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
525526
|-|-|-|-|-|-
526527
| 0027 |[Remove Element](src/main/python/g0001_0100/s0027_remove_element/Solution0027.py)| Easy | Array, Two_Pointers | 0 | 100.00
527528
| 0026 |[Remove Duplicates from Sorted Array](src/main/python/g0001_0100/s0026_remove_duplicates_from_sorted_array/Solution0026.py)| Easy | Top_Interview_Questions, Array, Two_Pointers | 0 | 100.00
529+
| 0080 |[Remove Duplicates from Sorted Array II](src/main/python/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution0080.py)| Medium | Array, Two_Pointers | 73 | 96.40
528530
| 0169 |[Majority Element](src/main/python/g0101_0200/s0169_majority_element/Solution0169.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 7 | 56.72
529531
| 0189 |[Rotate Array](src/main/python/g0101_0200/s0189_rotate_array/Solution0189.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 3 | 74.65
530532
| 0121 |[Best Time to Buy and Sell Stock](src/main/python/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution0121.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 17 | 98.03
@@ -538,6 +540,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
538540
| 0014 |[Longest Common Prefix](src/main/python/g0001_0100/s0014_longest_common_prefix/Solution0014.py)| Easy | Top_Interview_Questions, String, Big_O_Time_O(n\*m)_Space_O(m) | 0 | 100.00
539541
| 0006 |[Zigzag Conversion](src/main/python/g0001_0100/s0006_zigzag_conversion/Solution0006.py)| Medium | String, Big_O_Time_O(n)_Space_O(n) | 5 | 93.09
540542
| 0028 |[Implement strStr()](src/main/python/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution0028.py)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00
543+
| 0068 |[Text Justification](src/main/python/g0001_0100/s0068_text_justification/Solution0068.py)| Hard | Array, String, Simulation, 2025_09_13_Time_0_ms_(100.00%)_Space_17.85_MB_(62.97%) | |
541544

542545
#### Top Interview 150 Two Pointers
543546

@@ -583,6 +586,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
583586
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
584587
|-|-|-|-|-|-
585588
| 0020 |[Valid Parentheses](src/main/python/g0001_0100/s0020_valid_parentheses/Solution0020.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
589+
| 0071 |[Simplify Path](src/main/python/g0001_0100/s0071_simplify_path/Solution0071.py)| Medium | String, Stack | 0 | 100.00
586590
| 0155 |[Min Stack](src/main/python/g0101_0200/s0155_min_stack/MinStack.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 3 | 83.83
587591

588592
#### Top Interview 150 Linked List
@@ -595,6 +599,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
595599
| 0138 |[Copy List with Random Pointer](src/main/python/g0101_0200/s0138_copy_list_with_random_pointer/Solution0138.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 38 | 77.31
596600
| 0025 |[Reverse Nodes in k-Group](src/main/python/g0001_0100/s0025_reverse_nodes_in_k_group/Solution0025.py)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00
597601
| 0019 |[Remove Nth Node From End of List](src/main/python/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution0019.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
602+
| 0082 |[Remove Duplicates from Sorted List II](src/main/python/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution0082.py)| Medium | Two_Pointers, Linked_List | 0 | 100.00
598603
| 0061 |[Rotate List](src/main/python/g0001_0100/s0061_rotate_list/Solution0061.py)| Medium | Two_Pointers, Linked_List | 0 | 100.00
599604
| 0146 |[LRU Cache](src/main/python/g0101_0200/s0146_lru_cache/LRUCache.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 113 | 84.08
600605

@@ -646,6 +651,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
646651
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
647652
|-|-|-|-|-|-
648653
| 0017 |[Letter Combinations of a Phone Number](src/main/python/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution0017.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, LeetCode_75_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
654+
| 0077 |[Combinations](src/main/python/g0001_0100/s0077_combinations/Solution0077.py)| Medium | Backtracking | 91 | 95.48
649655
| 0046 |[Permutations](src/main/python/g0001_0100/s0046_permutations/Solution0046.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 0 | 100.00
650656
| 0039 |[Combination Sum](src/main/python/g0001_0100/s0039_combination_sum/Solution0039.py)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 4 | 90.51
651657
| 0022 |[Generate Parentheses](src/main/python/g0001_0100/s0022_generate_parentheses/Solution0022.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00
@@ -874,6 +880,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
874880
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
875881
|-|-|-|-|-|-
876882
| 0160 |[Intersection of Two Linked Lists](src/main/python/g0101_0200/s0160_intersection_of_two_linked_lists/Solution0160.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 83 | 67.29
883+
| 0082 |[Remove Duplicates from Sorted List II](src/main/python/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution0082.py)| Medium | Two_Pointers, Linked_List | 0 | 100.00
877884

878885
#### Day 12 Linked List
879886

@@ -996,6 +1003,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
9961003

9971004
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
9981005
|-|-|-|-|-|-
1006+
| 0077 |[Combinations](src/main/python/g0001_0100/s0077_combinations/Solution0077.py)| Medium | Backtracking | 91 | 95.48
9991007
| 0046 |[Permutations](src/main/python/g0001_0100/s0046_permutations/Solution0046.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 0 | 100.00
10001008

10011009
#### Day 12 Dynamic Programming
@@ -1036,6 +1044,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
10361044

10371045
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10381046
|-|-|-|-|-|-
1047+
| 0082 |[Remove Duplicates from Sorted List II](src/main/python/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution0082.py)| Medium | Two_Pointers, Linked_List | 0 | 100.00
10391048
| 0015 |[3Sum](src/main/python/g0001_0100/s0015_3sum/Solution0015.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 581 | 56.92
10401049

10411050
#### Day 4 Two Pointers
@@ -1684,14 +1693,19 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
16841693
| 0096 |[Unique Binary Search Trees](src/main/python/g0001_0100/s0096_unique_binary_search_trees/Solution0096.py)| Medium | Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Dynamic_Programming_I_Day_11, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
16851694
| 0094 |[Binary Tree Inorder Traversal](src/main/python/g0001_0100/s0094_binary_tree_inorder_traversal/Solution0094.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Data_Structure_I_Day_10_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
16861695
| 0084 |[Largest Rectangle in Histogram](src/main/python/g0001_0100/s0084_largest_rectangle_in_histogram/Solution0084.py)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n_log_n)_Space_O(log_n) | 63 | 99.53
1696+
| 0082 |[Remove Duplicates from Sorted List II](src/main/python/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/Solution0082.py)| Medium | Two_Pointers, Linked_List, Data_Structure_II_Day_11_Linked_List, Algorithm_II_Day_3_Two_Pointers, Top_Interview_150_Linked_List | 0 | 100.00
1697+
| 0080 |[Remove Duplicates from Sorted Array II](src/main/python/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/Solution0080.py)| Medium | Array, Two_Pointers, Udemy_Arrays, Top_Interview_150_Array/String | 73 | 96.40
16871698
| 0079 |[Word Search](src/main/python/g0001_0100/s0079_word_search/Solution0079.py)| 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) | 623 | 94.85
16881699
| 0078 |[Subsets](src/main/python/g0001_0100/s0078_subsets/Solution0078.py)| 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
1700+
| 0077 |[Combinations](src/main/python/g0001_0100/s0077_combinations/Solution0077.py)| Medium | Backtracking, Algorithm_I_Day_11_Recursion_Backtracking, Top_Interview_150_Backtracking | 91 | 95.48
16891701
| 0076 |[Minimum Window Substring](src/main/python/g0001_0100/s0076_minimum_window_substring/Solution0076.py)| 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) | 59 | 88.78
16901702
| 0075 |[Sort Colors](src/main/python/g0001_0100/s0075_sort_colors/Solution0075.py)| 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
16911703
| 0074 |[Search a 2D Matrix](src/main/python/g0001_0100/s0074_search_a_2d_matrix/Solution0074.py)| 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
16921704
| 0073 |[Set Matrix Zeroes](src/main/python/g0001_0100/s0073_set_matrix_zeroes/Solution0073.py)| 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) | 3 | 71.07
16931705
| 0072 |[Edit Distance](src/main/python/g0001_0100/s0072_edit_distance/Solution0072.py)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, 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) | 23 | 98.84
1706+
| 0071 |[Simplify Path](src/main/python/g0001_0100/s0071_simplify_path/Solution0071.py)| Medium | String, Stack, Top_Interview_150_Stack | 0 | 100.00
16941707
| 0070 |[Climbing Stairs](src/main/python/g0001_0100/s0070_climbing_stairs/Solution0070.py)| 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
1708+
| 0068 |[Text Justification](src/main/python/g0001_0100/s0068_text_justification/Solution0068.py)| Hard | Array, String, Simulation, Top_Interview_150_Array/String, 2025_09_13_Time_0_ms_(100.00%)_Space_17.85_MB_(62.97%) | |
16951709
| 0067 |[Add Binary](src/main/python/g0001_0100/s0067_add_binary/Solution0067.py)| Easy | String, Math, Bit_Manipulation, Simulation, Programming_Skills_II_Day_5, Top_Interview_150_Bit_Manipulation | 0 | 100.00
16961710
| 0066 |[Plus One](src/main/python/g0001_0100/s0066_plus_one/Solution0066.py)| Easy | Top_Interview_Questions, Array, Math, Programming_Skills_II_Day_3, Udemy_Arrays, Top_Interview_150_Math | 0 | 100.00
16971711
| 0064 |[Minimum Path Sum](src/main/python/g0001_0100/s0064_minimum_path_sum/Solution0064.py)| 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) | 15 | 60.38
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# #Hard #Array #String #Simulation #Top_Interview_150_Array/String
2+
# #2025_09_13_Time_0_ms_(100.00%)_Space_17.85_MB_(62.97%)
3+
4+
from typing import List
5+
6+
class Solution:
7+
def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:
8+
# Trying to gauge the number of lines so the list doesn't need to resize
9+
output = []
10+
# Setting string capacity also
11+
sb = []
12+
line_total = 0
13+
num_words_on_line = 0
14+
start_word = 0
15+
# looping until the 2nd last word, since we're checking words[i + 1] for overflows
16+
for i in range(len(words) - 1):
17+
line_total += len(words[i])
18+
# tracking line length + #words
19+
num_words_on_line += 1
20+
# checking if the next word causes an overflow
21+
if line_total + num_words_on_line + len(words[i + 1]) > maxWidth:
22+
# if only one word fits on the line...
23+
if num_words_on_line == 1:
24+
# append word
25+
sb.append(words[i])
26+
# pad right with spaces
27+
while line_total < maxWidth:
28+
sb.append(' ')
29+
line_total += 1
30+
else:
31+
# # of extra spaces
32+
extra_sp = (maxWidth - line_total) % (num_words_on_line - 1)
33+
# Creating the line
34+
for j in range(start_word, start_word + num_words_on_line - 1):
35+
# appending the word
36+
sb.append(words[j])
37+
if extra_sp > 0:
38+
# appending an extra space, if required
39+
sb.append(' ')
40+
extra_sp -= 1
41+
# appending the rest of the required spaces
42+
max_spaces = max(0, (maxWidth - line_total) // (num_words_on_line - 1))
43+
sb.append(' ' * max_spaces)
44+
# appending the last word of the line
45+
sb.append(words[start_word + num_words_on_line - 1])
46+
# adding to output list
47+
output.append(''.join(sb))
48+
# reset everything for next line
49+
# keeping track of the first word for next line
50+
start_word = i + 1
51+
# resetting these to 0 for processing next line
52+
num_words_on_line = line_total = 0
53+
# need a new list for the next line
54+
sb = []
55+
# handling the final line (no justification, right padded with spaces)
56+
line_total = 0
57+
for i in range(start_word, len(words)):
58+
line_total += len(words[i])
59+
sb.append(words[i])
60+
if line_total < maxWidth:
61+
sb.append(' ')
62+
line_total += 1
63+
# padding right side with spaces
64+
while line_total < maxWidth:
65+
sb.append(' ')
66+
line_total += 1
67+
# add the final line to output list
68+
output.append(''.join(sb))
69+
return output
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import unittest
2+
from Solution0068 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_fullJustify(self):
6+
input_words = ["This", "is", "an", "example", "of", "text", "justification."]
7+
actual = Solution().fullJustify(input_words, 16)
8+
expected = [
9+
"This is an",
10+
"example of text",
11+
"justification. "
12+
]
13+
self.assertEqual(actual, expected)
14+
15+
def test_fullJustify2(self):
16+
input_words = ["What", "must", "be", "acknowledgment", "shall", "be"]
17+
actual = Solution().fullJustify(input_words, 16)
18+
expected = [
19+
"What must be",
20+
"acknowledgment ",
21+
"shall be "
22+
]
23+
self.assertEqual(actual, expected)
24+
25+
def test_fullJustify3(self):
26+
input_words = [
27+
"Science", "is", "what", "we", "understand", "well", "enough", "to",
28+
"explain", "to", "a", "computer.", "Art", "is", "everything", "else", "we", "do"
29+
]
30+
actual = Solution().fullJustify(input_words, 20)
31+
expected = [
32+
"Science is what we",
33+
"understand well",
34+
"enough to explain to",
35+
"a computer. Art is",
36+
"everything else we",
37+
"do "
38+
]
39+
self.assertEqual(actual, expected)

0 commit comments

Comments
 (0)