From 3ea9fc7f178e3d89ad2afa50218b81d1c0d2987b Mon Sep 17 00:00:00 2001 From: Ryan Maleki Date: Sun, 19 Jan 2025 21:34:31 -0800 Subject: [PATCH 1/4] for example, return pattern --- array/add_two_numbers_test.go | 7 +++++-- array/equal_sum_subarrays_test.go | 2 +- array/product_of_all_other_elements_test.go | 2 +- array/reverse_inplace_test.go | 2 +- array/rotate_k_steps_test.go | 9 +++++---- greedy/max_number_test.go | 5 +++-- linkedlist/join_sorted_lists_test.go | 2 +- linkedlist/keep_repetitions_test.go | 2 +- linkedlist/reverse_in_place_test.go | 2 +- recursion/expression_operators_test.go | 2 +- 10 files changed, 20 insertions(+), 15 deletions(-) diff --git a/array/add_two_numbers_test.go b/array/add_two_numbers_test.go index da3dd6b..9a990dc 100644 --- a/array/add_two_numbers_test.go +++ b/array/add_two_numbers_test.go @@ -10,8 +10,11 @@ TestAddTwoNumbers tests solution(s) with the following signature and problem des AddTwoNumbers(num1, num2 []int) []int -Given two positive integers represented as a slice like {2,9} and {9,9,9} return their sum like {1,0,2,8}. -because 29+999=1028. +A slice representation of a positive integer like 283 looks like {2,8,3}. Given two positive +integers represented in this format return their sum in the same format. + +For example given {2,9} and {9,9,9}, return {1,0,2,8}. +Because 29+999=1028. */ func TestAddTwoNumbers(t *testing.T) { tests := []struct { diff --git a/array/equal_sum_subarrays_test.go b/array/equal_sum_subarrays_test.go index 7acb319..19a4cbb 100644 --- a/array/equal_sum_subarrays_test.go +++ b/array/equal_sum_subarrays_test.go @@ -13,7 +13,7 @@ TestEqualSumSubArrays tests solution(s) with the following signature and problem Given an list of integers A, return two sub-arrays with equal sums without changing the order of the elements in the list. -For example if given {1,7,3,5} return {1,7} and {3,5} because 1+7 = 3+5 = 8. +For example given {1,7,3,5, return {1,7} and {3,5} because 1+7 = 3+5 = 8. */ func TestEqualSumSubArrays(t *testing.T) { tests := []struct { diff --git a/array/product_of_all_other_elements_test.go b/array/product_of_all_other_elements_test.go index b3c8644..7669704 100644 --- a/array/product_of_all_other_elements_test.go +++ b/array/product_of_all_other_elements_test.go @@ -13,7 +13,7 @@ TestProductOfAllOtherElements tests solution(s) with the following signature and Given an array of integers A, construct a new array B such that B[i] = product of all items in A except A[i] without using division in O(n) time. -For example given {1,2,3,4} it should return {24,12,8,6} because: +For example given {1,2,3,4}, return {24,12,8,6} because: * 24=2*3*4. * 12=1*3*4. * 8=1*2*4. diff --git a/array/reverse_inplace_test.go b/array/reverse_inplace_test.go index d3aaa7e..49dee65 100644 --- a/array/reverse_inplace_test.go +++ b/array/reverse_inplace_test.go @@ -13,7 +13,7 @@ TestReverseInPlace tests solution(s) with the following signature and problem de Given a slice of integers, a start index, and an end index, reverse the integers in the in-place without using any extra memory. -For example given {1,2,3,4,5,6} and start of 0 and end of 4, it should return {5,4,3,2,1,6} because: +For example given {1,2,3,4,5,6} and start of 0 and end of 4, return {5,4,3,2,1,6} because: Reverse of items from index 0 to 4 is {5,4,3,2,1} and the remaining item {6} remain unchanged, so the the resulting slice is {5,4,3,2,1,6}. diff --git a/array/rotate_k_steps_test.go b/array/rotate_k_steps_test.go index b4817a2..c3904ee 100644 --- a/array/rotate_k_steps_test.go +++ b/array/rotate_k_steps_test.go @@ -12,10 +12,11 @@ TestRotateKSteps tests solution(s) with the following signature and problem desc Given an list of integers and a number k, rotate the array k times. -For example if given {1,2,3} and 3, it should return {1,2,3} because. -Slice after 1 rotation: {3,1,2}. -Slice after 2 rotations: {2,3,1}. -Slice after 3 rotations: {1,2,3}. +For example given {1,2,3} and 3, return {1,2,3} because: + +After 1 rotation: {3,1,2}. +After 2 rotations: {2,3,1}. +After 3 rotations: {1,2,3}. */ func TestRotateKSteps(t *testing.T) { tests := []struct { diff --git a/greedy/max_number_test.go b/greedy/max_number_test.go index ad589d7..0496b2e 100644 --- a/greedy/max_number_test.go +++ b/greedy/max_number_test.go @@ -14,8 +14,9 @@ Given two numbers represented as list of positive integers, and an integer n, re largest possible integer with n digits that can be constructed by merging digits from two numbers while respecting the order of digits in each number. -For example given {5, 4, 3, 2, 1}, {9, 8, 7, 6} and 9, it should return a 9 digit number -{9, 8, 7, 6, 5, 4, 3, 2, 1}. +For example given {5, 4, 3, 2, 1}, {9, 8, 7, 6} and 9, return +{9, 8, 7, 6, 5, 4, 3, 2, 1} because it is the largest 9 digit combination of all elements +of the two given slices. */ func TestMaxNumber(t *testing.T) { tests := []struct { diff --git a/linkedlist/join_sorted_lists_test.go b/linkedlist/join_sorted_lists_test.go index adc6b06..f8c36c3 100644 --- a/linkedlist/join_sorted_lists_test.go +++ b/linkedlist/join_sorted_lists_test.go @@ -9,7 +9,7 @@ TestJoinTwoSortedLinkedLists tests solution(s) with the following signature and Given two sorted linked lists of integers, merge them into one sorted linked list. -For example if given 1->4->6 and 2->3->5->7, the output should be 1->2->3->4->5->6->7. +For example given 1->4->6 and 2->3->5->7, return 1->2->3->4->5->6->7. */ func TestJoinTwoSortedLinkedLists(t *testing.T) { tests := []struct { diff --git a/linkedlist/keep_repetitions_test.go b/linkedlist/keep_repetitions_test.go index 84d2e49..d597534 100644 --- a/linkedlist/keep_repetitions_test.go +++ b/linkedlist/keep_repetitions_test.go @@ -10,7 +10,7 @@ TestKeepRepetitions tests solution(s) with the following signature and problem d Given a linked list of sorted integers, create a copy of the list that contains one example of each repeated item. -For example if the linked list is 1->1->4->4->6->6->7, the output should be 1->4->6 because +For example given 1->1->4->4->6->6->7, return 1->4->6 because 1,4,6 are items that are repeated in this list and 7 is not repeated. */ func TestKeepRepetitions(t *testing.T) { diff --git a/linkedlist/reverse_in_place_test.go b/linkedlist/reverse_in_place_test.go index 3e58c43..b644b82 100644 --- a/linkedlist/reverse_in_place_test.go +++ b/linkedlist/reverse_in_place_test.go @@ -12,7 +12,7 @@ TestReverseLinkedList tests solution(s) with the following signature and problem func ReverseLinkedList(head *Node) *Node -Reverse a given linked list in place. For example if the linked list is 1->2->3 return 3->2->1. +Reverse a linked list in place. For example given 1->2->3, return 3->2->1. */ func TestReverseLinkedList(t *testing.T) { tests := []struct { diff --git a/recursion/expression_operators_test.go b/recursion/expression_operators_test.go index 15578dc..e76fbb7 100644 --- a/recursion/expression_operators_test.go +++ b/recursion/expression_operators_test.go @@ -12,7 +12,7 @@ the result of the equation, return a string representing operators that can be i the operands to form the equation and yield the target result. Only + and - operators are allowed and the are assumed to have the same priority -For example given {1,5,3} and 3, it should return +- because 1+5-3 = 3. +For example given {1,5,3} and 3, return +- because 1+5-3 = 3. */ func TestExpressionOperators(t *testing.T) { tests := []struct { From bfbeb3706ea0e012a6d92e40e350508fdfe960aa Mon Sep 17 00:00:00 2001 From: Ryan Maleki Date: Sun, 19 Jan 2025 22:19:50 -0800 Subject: [PATCH 2/4] Problem title clean up --- README.md | 36 +++++++++---------- array/README.md | 2 +- ...two_numbers.go => add_slice_of_numbers.go} | 4 +-- ...s_test.go => add_slice_of_numbers_test.go} | 6 ++-- bit/README.md | 8 ++--- bit/addition_without_operators.go | 4 +-- bit/addition_without_operators_test.go | 8 ++--- ...go => max_without_comparison_operators.go} | 0 ... max_without_comparison_operators_test.go} | 2 +- dp/README.md | 2 +- ...go => min_deletions_to_make_palindrome.go} | 4 +-- ... min_deletions_to_make_palindrome_test.go} | 6 ++-- graph/README.md | 2 +- greedy/README.md | 4 +-- heap/README.md | 2 +- heap/{sliding_maximum.go => sliding_max.go} | 0 ...ng_maximum_test.go => sliding_max_test.go} | 0 linkedlist/README.md | 2 +- queue/README.md | 8 ++--- ..._of_sub_arrays.go => max_of_sub_arrays.go} | 0 ...rays_test.go => max_of_sub_arrays_test.go} | 10 ++++-- ...metrical.go => symmetrical_binary_tree.go} | 0 ...est.go => symmetrical_binary_tree_test.go} | 0 recursion/README.md | 2 +- ...r_expressions.go => regular_expression.go} | 0 ...ons_test.go => regular_expression_test.go} | 0 strings/README.md | 2 +- tree/README.md | 2 +- tree/{auto_complete.go => autocompletion.go} | 4 +-- ...omplete_test.go => autocompletion_test.go} | 6 ++-- 30 files changed, 65 insertions(+), 61 deletions(-) rename array/{add_two_numbers.go => add_slice_of_numbers.go} (84%) rename array/{add_two_numbers_test.go => add_slice_of_numbers_test.go} (77%) rename bit/{max_function_without_conditions.go => max_without_comparison_operators.go} (100%) rename bit/{max_function_without_conditions_test.go => max_without_comparison_operators_test.go} (90%) rename dp/{minimum_deletion_to_make_palindrome.go => min_deletions_to_make_palindrome.go} (78%) rename dp/{minimum_deletion_to_make_palindrome_test.go => min_deletions_to_make_palindrome_test.go} (70%) rename heap/{sliding_maximum.go => sliding_max.go} (100%) rename heap/{sliding_maximum_test.go => sliding_max_test.go} (100%) rename queue/{maximum_of_sub_arrays.go => max_of_sub_arrays.go} (100%) rename queue/{maximum_of_sub_arrays_test.go => max_of_sub_arrays_test.go} (71%) rename queue/{is_tree_symmetrical.go => symmetrical_binary_tree.go} (100%) rename queue/{is_tree_symmetrical_test.go => symmetrical_binary_tree_test.go} (100%) rename recursion/{regular_expressions.go => regular_expression.go} (100%) rename recursion/{regular_expressions_test.go => regular_expression_test.go} (100%) rename tree/{auto_complete.go => autocompletion.go} (91%) rename tree/{auto_complete_test.go => autocompletion_test.go} (90%) diff --git a/README.md b/README.md index 91ca8b8..031fd50 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design * Data Structures * [Arrays](./array/README.md) * [Reverse Array In-place](./array/reverse_inplace_test.go) - * [Add Two Numbers](./array/add_two_numbers_test.go) + * [Add Two Numbers Represented as Slices](./array/add_slice_of_numbers_test.go) * [Find Duplicate in Array](./array/find_duplicate_in_array_test.go) * [Zero Sum Triplets](./array/zero_sum_triplets_test.go) * [Product of All Other Elements](./array/product_of_all_other_elements_test.go) @@ -35,12 +35,12 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design * [Look and Tell](./strings/look_and_tell_test.go) * [In Memory Database](./strings/in_memory_database_test.go) * [Number in English](./strings/number_in_english_test.go) - * [Reverse Vowels In a String](./strings/reverse_vowels_test.go) + * [Reverse Vowels in a String](./strings/reverse_vowels_test.go) * [Longest Substring of Two Unique Characters](./strings/longest_substring_test.go) * [Roman Numerals](./strings/roman_numerals_test.go) * [Linked Lists](./linkedlist/README.md) * [Linked List Serialization](./linkedlist/serialization_test.go) - * [Reverse a Linked List In-place](./linkedlist/reverse_in_place_test.go) + * [Reverse Linked List In-place](./linkedlist/reverse_in_place_test.go) * [Join Two Sorted Linked Lists](./linkedlist/join_sorted_lists_test.go) * [Keep Repetitions](./linkedlist/keep_repetitions_test.go) * [Copy Linked List with Random Pointer](./linkedlist/copy_linklist_with_random_pointer_test.go) @@ -53,11 +53,11 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design * [Basic Calculator](./stack/basic_calculator_test.go) * [Longest Valid Parentheses](./stack/longest_valid_parentheses_test.go) * [Queues](./queue/README.md) - * [A Queue Using Stacks](./queue/queue_using_stacks_test.go) - * [Implement a Circular Queue Array](./queue/circular_queue_using_array_test.go) - * [Is Binary Tree Symmetrical](./queue/is_tree_symmetrical_test.go) + * [Queue Using Stacks](./queue/queue_using_stacks_test.go) + * [Circular Queue Array](./queue/circular_queue_using_array_test.go) + * [Symmetrical Binary Tree](./queue/symmetrical_binary_tree_test.go) * [Generate Binary Numbers](./queue/generate_binary_numbers_test.go) - * [Find The Maximum Sub-array of Length K](./queue/maximum_of_sub_arrays_test.go) + * [Max Sub-array of size K](./queue/max_of_sub_arrays_test.go) * [String Permutations](./queue/string_permutations_test.go) * [Hash Tables](./hashtable/README.md) * [Find Missing Number](./hashtable/missing_number_test.go) @@ -72,14 +72,14 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design * [Sorted Array to Balanced BST](./tree/sorted_array_to_balanced_bsd_test.go) * [Traverse Binary Tree](./tree/traverse_binary_tree_test.go) * [Reverse Binary Tree](./tree/reverse_binary_tree_test.go) - * [Implement Autocomplete](./tree/auto_complete_test.go) + * [Autocompletion](./tree/autocompletion_test.go) * [Heaps](./heap/README.md) * [Kth Largest Element](./heap/kth_largest_element_test.go) * [Merge Sorted Lists](./heap/merge_sorted_list_test.go) * [Median in a Stream](./heap/median_in_a_stream_test.go) * [Regular Numbers](./heap/regular_numbers_test.go) * [Kth Closest Points to the Center](./heap/k_closest_points_to_origin_test.go) - * [Sliding Maximum](./heap/sliding_maximum_test.go) + * [Sliding Max](./heap/sliding_max_test.go) * [Heap Sort](./heap/heap_sort_test.go) * Algorithms * [Recursion](./recursion/README.md) @@ -88,7 +88,7 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design * [Climbing Stairs](./recursion/climbing_stairs_test.go) * [Exponentiation](./recursion/exponentiation_test.go) * [Multiplication](./recursion/multiplication_test.go) - * [Regular Expressions Matching](./recursion/regular_expressions_test.go) + * [Regular Expression Matching](./recursion/regular_expression_test.go) * [Expression Operators](./recursion/expression_operators_test.go) * [Divide and Conquer](./dnc/README.md) * [Binary Search](./dnc/binary_search_test.go) @@ -98,11 +98,11 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design * [Merge Sort](./dnc/merge_sort_test.go) * [Quick Sort](./dnc/quick_sort_test.go) * [Bit Manipulation](./bit/README.md) - * [Division without multiplication or division operators](./bit/division_without_operators_test.go) - * [Middle without division](./bit/middle_without_division_test.go) - * [Addition without using plus (+) or any other arithmetic operators](./bit/addition_without_operators_test.go) + * [Division Without Multiplication or Division Operators](./bit/division_without_operators_test.go) + * [Middle Without Division](./bit/middle_without_division_test.go) + * [Addition Without Arithmetic Operators](./bit/addition_without_operators_test.go) * [Power of Two](./bit/is_power_of_two_test.go) - * [Maximum without if conditions](./bit/max_function_without_conditions_test.go) + * [Max Without Comparison Operators](./bit/max_without_comparison_operators_test.go) * [Oddly Repeated Number](./bit/oddly_repeated_number_test.go) * [Backtracking](./backtracking/README.md) * [Permutations](./backtracking/permutations_test.go) @@ -113,7 +113,7 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design * [N Queens](./backtracking/n_queens_test.go) * [Graphs](./graph/README.md) * [Iteratively Implement BFS and DFS](./graph/iterative_traversal_test.go) - * [Is Graph a DAG](./graph/is_dag_test.go) + * [DAG Graphs](./graph/is_dag_test.go) * [Topological Sort](./graph/topological_sort_test.go) * [Employee Headcount](./graph/employee_headcount_test.go) * [Remove Invalid Parentheses](./graph/remove_invalid_parentheses_test.go) @@ -124,18 +124,18 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design * [Number of Islands](./graph/number_of_islands_test.go) * [Dependency Order](./graph/dependency_order_test.go) * [Greedy Algorithms](./greedy/README.md) - * [Maximum Stock Profit](./greedy/max_stock_profit_test.go) + * [Max Stock Profit](./greedy/max_stock_profit_test.go) * [Activity Selector](./greedy/activity_selector_test.go) * [Knapsack](./greedy/knapsack_test.go) * [Jump Game](./greedy/jump_game_test.go) - * [Maximum Number](./greedy/max_number_test.go) + * [Max Number](./greedy/max_number_test.go) * [Task Scheduling](./greedy/task_scheduling_test.go) * [Dynamic Programming](./dp/README.md) * [Rod Cutting](./dp/rod_cutting_test.go) * [Sum Up to Number](./dp/sum_up_to_integer_test.go) * [House Robber](./dp/house_robber_test.go) * [Interleaving String](./dp/interleaving_string_test.go) - * [Minimum Deletion to Make a Palindrome](./dp/minimum_deletion_to_make_palindrome_test.go) + * [Min Deletions to Make a Palindrome](./dp/min_deletions_to_make_palindrome_test.go) * [Word Distance](./dp/word_distance_test.go) ## 📋 Outline diff --git a/array/README.md b/array/README.md index 2f3853c..8f3d3cc 100644 --- a/array/README.md +++ b/array/README.md @@ -87,7 +87,7 @@ Arrays are used wherever sequential data or more than one piece of data is neede ## Rehearsal * [Reverse Array In-place](./reverse_inplace_test.go), [Solution](./reverse_inplace.go) -* [Add Two Numbers](./add_two_numbers_test.go), [Solution](./add_two_numbers.go) +* [Add Two Numbers Represented as Slices](./add_slice_of_numbers_test.go), [Solution](./add_slice_of_numbers.go) * [Find Duplicate in Array](./find_duplicate_in_array_test.go), [Solution](./find_duplicate_in_array.go) * [Zero Sum Triplets](./zero_sum_triplets_test.go), [Solution](./zero_sum_triplets.go) * [Product of All Other Elements](./product_of_all_other_elements_test.go), [Solution](./product_of_all_other_elements.go) diff --git a/array/add_two_numbers.go b/array/add_slice_of_numbers.go similarity index 84% rename from array/add_two_numbers.go rename to array/add_slice_of_numbers.go index fade5f6..7d8dd78 100644 --- a/array/add_two_numbers.go +++ b/array/add_slice_of_numbers.go @@ -1,7 +1,7 @@ package array -// AddTwoNumbers solves the problem in O(n) time and O(1) space. -func AddTwoNumbers(num1, num2 []int) []int { +// AddSliceOfTwoNumbers solves the problem in O(n) time and O(1) space. +func AddSliceOfTwoNumbers(num1, num2 []int) []int { num1, num2 = equalizeLengths(num1, num2) carry := false for i := len(num1) - 1; i > -1; i-- { diff --git a/array/add_two_numbers_test.go b/array/add_slice_of_numbers_test.go similarity index 77% rename from array/add_two_numbers_test.go rename to array/add_slice_of_numbers_test.go index 9a990dc..81d4c41 100644 --- a/array/add_two_numbers_test.go +++ b/array/add_slice_of_numbers_test.go @@ -6,7 +6,7 @@ import ( ) /* -TestAddTwoNumbers tests solution(s) with the following signature and problem description: +TestAddSliceOfTwoNumbers tests solution(s) with the following signature and problem description: AddTwoNumbers(num1, num2 []int) []int @@ -16,7 +16,7 @@ integers represented in this format return their sum in the same format. For example given {2,9} and {9,9,9}, return {1,0,2,8}. Because 29+999=1028. */ -func TestAddTwoNumbers(t *testing.T) { +func TestAddSliceOfTwoNumbers(t *testing.T) { tests := []struct { num1, num2, sum []int }{ @@ -29,7 +29,7 @@ func TestAddTwoNumbers(t *testing.T) { {[]int{9, 9, 9}, []int{9, 9, 9}, []int{1, 9, 9, 8}}, } for i, test := range tests { - if got := AddTwoNumbers(test.num1, test.num2); !slices.Equal(got, test.sum) { + if got := AddSliceOfTwoNumbers(test.num1, test.num2); !slices.Equal(got, test.sum) { t.Fatalf("Failed test case #%d. Want %v got %v", i, test.sum, got) } } diff --git a/bit/README.md b/bit/README.md index e4921a0..ffe40fc 100644 --- a/bit/README.md +++ b/bit/README.md @@ -108,9 +108,9 @@ Negation can be used to invert a set of flags or find the two's complement of a ## Rehearsal -* [Division without multiplication or division operators](./division_without_operators_test.go), [Solution](./division_without_operators.go) -* [Middle without division](./middle_without_division_test.go), [Solution](./middle_without_division.go) -* [Addition without using plus (+) or any other arithmetic operators](./addition_without_operators_test.go), [Solution](./addition_without_operators.go) +* [Division Without Multiplication or Division Operators](./division_without_operators_test.go), [Solution](./division_without_operators.go) +* [Middle Without Division](./middle_without_division_test.go), [Solution](./middle_without_division.go) +* [Addition Without Arithmetic Operators](./addition_without_operators_test.go), [Solution](./addition_without_operators.go) * [Power of Two](./is_power_of_two_test.go), [Solution](./is_power_of_two.go) -* [Maximum without if conditions](./max_function_without_conditions_test.go), [Solution](./max_function_without_conditions.go) +* [Max Without Comparison Operators](./max_without_comparison_operators_test.go), [Solution](./max_without_comparison_operators.go) * [Oddly Repeated Number](./oddly_repeated_number_test.go), [Solution](./oddly_repeated_number.go) diff --git a/bit/addition_without_operators.go b/bit/addition_without_operators.go index e21fbd1..141fab8 100644 --- a/bit/addition_without_operators.go +++ b/bit/addition_without_operators.go @@ -1,7 +1,7 @@ package bit -// Add solves the problem in O(1) time and O(1) space. -func Add(x, y int) int { +// AdditionWithoutArithmeticOperators solves the problem in O(1) time and O(1) space. +func AdditionWithoutArithmeticOperators(x, y int) int { for y != 0 { sum := x ^ y carry := (x & y) << 1 diff --git a/bit/addition_without_operators_test.go b/bit/addition_without_operators_test.go index 1d0fdc5..02c3bd2 100644 --- a/bit/addition_without_operators_test.go +++ b/bit/addition_without_operators_test.go @@ -3,13 +3,13 @@ package bit import "testing" /* -TestAdd tests solution(s) with the following signature and problem description: +TestAdditionWithoutArithmeticOperators tests solution(s) with the following signature and problem description: func Add(x, y int) int -Add x by y, two integers without using the built-in + or any other arithmetic operators. +Add x by y, two integers without using any arithmetic operators such as {+,-,/,*,++,--,+=,...} */ -func TestAdd(t *testing.T) { +func TestAdditionWithoutArithmeticOperators(t *testing.T) { tests := []struct { a, b int }{ @@ -20,7 +20,7 @@ func TestAdd(t *testing.T) { } for i, test := range tests { - got := Add(test.a, test.b) + got := AdditionWithoutArithmeticOperators(test.a, test.b) want := test.a + test.b if got != want { t.Fatalf("Failed test case #%d. Want %#v got %#v", i, want, got) diff --git a/bit/max_function_without_conditions.go b/bit/max_without_comparison_operators.go similarity index 100% rename from bit/max_function_without_conditions.go rename to bit/max_without_comparison_operators.go diff --git a/bit/max_function_without_conditions_test.go b/bit/max_without_comparison_operators_test.go similarity index 90% rename from bit/max_function_without_conditions_test.go rename to bit/max_without_comparison_operators_test.go index e95c4d3..9afcf7d 100644 --- a/bit/max_function_without_conditions_test.go +++ b/bit/max_without_comparison_operators_test.go @@ -8,7 +8,7 @@ TestMax tests solution(s) with the following signature and problem description: func Max(x, y int) int Write max, a function that returns the largest of two numbers without using a -comparison or if conditions. +any of the comparison operators such as {if, switch,...}. */ func TestMax(t *testing.T) { tests := []struct { diff --git a/dp/README.md b/dp/README.md index 7392fb3..0165eda 100644 --- a/dp/README.md +++ b/dp/README.md @@ -94,5 +94,5 @@ DP is well-suited for tackling complex problems, including logistics, game theor * [Sum Up to Number](./sum_up_to_integer_test.go), [Solution](./sum_up_to_integer.go) * [House Robber](./house_robber_test.go), [Solution](./house_robber.go). * [Interleaving String](./interleaving_string_test.go), [Solution](./interleaving_string.go) -* [Minimum Deletion to Make a Palindrome](./minimum_deletion_to_make_palindrome_test.go), [Solution](./minimum_deletion_to_make_palindrome.go) +* [Min Deletions to Make a Palindrome](./min_deletions_to_make_palindrome_test.go), [Solution](./min_deletions_to_make_palindrome.go) * [Word Distance](./word_distance_test.go), [Solution](./word_distance.go) diff --git a/dp/minimum_deletion_to_make_palindrome.go b/dp/min_deletions_to_make_palindrome.go similarity index 78% rename from dp/minimum_deletion_to_make_palindrome.go rename to dp/min_deletions_to_make_palindrome.go index 78b6b3c..6cb57b2 100644 --- a/dp/minimum_deletion_to_make_palindrome.go +++ b/dp/min_deletions_to_make_palindrome.go @@ -1,7 +1,7 @@ package dp -// MinimumDeletionsToMakePalindrome solves the problem in O(n^2) time and O(n^2) space. -func MinimumDeletionsToMakePalindrome(input string) int { +// MinDeletionsToMakePalindrome solves the problem in O(n^2) time and O(n^2) space. +func MinDeletionsToMakePalindrome(input string) int { if len(input) <= 1 { return 0 } diff --git a/dp/minimum_deletion_to_make_palindrome_test.go b/dp/min_deletions_to_make_palindrome_test.go similarity index 70% rename from dp/minimum_deletion_to_make_palindrome_test.go rename to dp/min_deletions_to_make_palindrome_test.go index 07b0efc..e41c8a4 100644 --- a/dp/minimum_deletion_to_make_palindrome_test.go +++ b/dp/min_deletions_to_make_palindrome_test.go @@ -3,14 +3,14 @@ package dp import "testing" /* -TestMinimumDeletionsToMakePalindrome tests solution(s) with the following signature and problem description: +TestMinDeletionsToMakePalindrome tests solution(s) with the following signature and problem description: func MinimumDeletionsToMakePalindrome(input string) int Given a string like abccb return the minimum number of character deletions that can be done on the string to make it a palindrome like 1 (by removing a, we will have bccb). */ -func TestMinimumDeletionsToMakePalindrome(t *testing.T) { +func TestMinDeletionsToMakePalindrome(t *testing.T) { tests := []struct { input string minChangeNeededToMakePalindrome int @@ -27,7 +27,7 @@ func TestMinimumDeletionsToMakePalindrome(t *testing.T) { } for i, test := range tests { - if got := MinimumDeletionsToMakePalindrome(test.input); got != test.minChangeNeededToMakePalindrome { + if got := MinDeletionsToMakePalindrome(test.input); got != test.minChangeNeededToMakePalindrome { t.Fatalf("Failed test case #%d. Want %d got %d", i, test.minChangeNeededToMakePalindrome, got) } } diff --git a/graph/README.md b/graph/README.md index 9e3f0aa..856ba0b 100644 --- a/graph/README.md +++ b/graph/README.md @@ -270,7 +270,7 @@ Graph algorithms find extensive usage in addressing real-world challenges, inclu ## Rehearsal * [Iteratively Implement BFS and DFS](./iterative_traversal_test.go), [Solution](./iterative_traversal.go) -* [Is Graph a DAG](./is_dag_test.go), [Solution](./is_dag.go) +* [DAG Graphs](./is_dag_test.go), [Solution](./is_dag.go) * [Topological Sort](./topological_sort_test.go), [Solution](./topological_sort.go) * [Employee Headcount](./employee_headcount_test.go), [Solution](./employee_headcount.go) * [Remove Invalid Parentheses](./remove_invalid_parentheses_test.go), [Solution](./remove_invalid_parentheses.go) diff --git a/greedy/README.md b/greedy/README.md index e8e93c4..56054f0 100644 --- a/greedy/README.md +++ b/greedy/README.md @@ -27,9 +27,9 @@ Greedy algorithms can be applied to optimization problems in which the aim is to ## Rehearsal -* [Maximum Stock Profit](./max_stock_profit_test.go), [Solution](./max_stock_profit.go) +* [Max Stock Profit](./max_stock_profit_test.go), [Solution](./max_stock_profit.go) * [Activity Selector](./activity_selector_test.go), [Solution](./activity_selector.go) * [Knapsack](./knapsack_test.go), [Solution](./knapsack.go) * [Jump Game](./jump_game_test.go), [Solution](./jump_game.go) -* [Maximum Number](./max_number_test.go), [Solution](./max_number.go) +* [Max Number](./max_number_test.go), [Solution](./max_number.go) * [Task Scheduling](./task_scheduling_test.go), [Solution](./task_scheduling.go) diff --git a/heap/README.md b/heap/README.md index 3ee86f4..1b4d124 100644 --- a/heap/README.md +++ b/heap/README.md @@ -99,4 +99,4 @@ Priority queues implemented as heaps are commonly used in job scheduling, for ex * [Median in a Stream](./median_in_a_stream_test.go), [Solution](./median_in_a_stream.go) * [Regular Numbers](./regular_numbers_test.go), [Solution](./regular_numbers.go) * [Kth Closest Points to the Center](./k_closest_points_to_origin_test.go), [Solution](./k_closest_points_to_origin.go) -* [Sliding Maximum](./sliding_maximum_test.go), [Solution](./sliding_maximum.go) +* [Sliding Max](./sliding_max_test.go), [Solution](./sliding_max.go) diff --git a/heap/sliding_maximum.go b/heap/sliding_max.go similarity index 100% rename from heap/sliding_maximum.go rename to heap/sliding_max.go diff --git a/heap/sliding_maximum_test.go b/heap/sliding_max_test.go similarity index 100% rename from heap/sliding_maximum_test.go rename to heap/sliding_max_test.go diff --git a/linkedlist/README.md b/linkedlist/README.md index 52f98a4..f9730cf 100644 --- a/linkedlist/README.md +++ b/linkedlist/README.md @@ -90,7 +90,7 @@ Linked lists can be useful where the order of items matters, especially if there ## Rehearsal * [Linked List Serialization](./serialization_test.go), [Solution](./serialization.go) -* [Reverse a Linked List In-place](./reverse_in_place_test.go), [Solution](./reverse_in_place.go) +* [Reverse Linked List In-place](./reverse_in_place_test.go), [Solution](./reverse_in_place.go) * [Join Two Sorted Linked Lists](./join_sorted_lists_test.go), [Solution](./join_sorted_lists.go) * [Keep Repetitions](./keep_repetitions_test.go), [Solution](./keep%20repetitions.go) * [Copy Linked List with Random Pointer](./copy_linklist_with_random_pointer_test.go), [Solution](./copy_linklist_with_random_pointer.go) diff --git a/queue/README.md b/queue/README.md index 1710dc8..f72e1e7 100644 --- a/queue/README.md +++ b/queue/README.md @@ -93,9 +93,9 @@ Queues are widely utilized in solving graph-related problems and managing capaci ## Rehearsal -* [A Queue Using Stacks](./queue_using_stacks_test.go), [Solution](./queue_using_stacks.go) -* [Implement a Circular Queue Array](./circular_queue_using_array_test.go), [Solution](./circular_queue_using_array.go) -* [Is Binary Tree Symmetrical](./is_tree_symmetrical_test.go), [Solution](./is_tree_symmetrical.go) +* [Queue Using Stacks](./queue_using_stacks_test.go), [Solution](./queue_using_stacks.go) +* [Circular Queue Array](./circular_queue_using_array_test.go), [Solution](./circular_queue_using_array.go) +* [Symmetrical Binary Tree](./symmetrical_binary_tree_test.go), [Solution](./symmetrical_binary_tree.go) * [Generate Binary Numbers](./generate_binary_numbers_test.go), [Solution](./generate_binary_numbers.go) -* [Find The Maximum Sub-array of Length K](./maximum_of_sub_arrays_test.go), [Solution](./maximum_of_sub_arrays.go) +* [Max Sub-array of size K](./max_of_sub_arrays_test.go), [Solution](./max_of_sub_arrays.go) * [String Permutations](./string_permutations_test.go), [Solution](./string_permutations.go) diff --git a/queue/maximum_of_sub_arrays.go b/queue/max_of_sub_arrays.go similarity index 100% rename from queue/maximum_of_sub_arrays.go rename to queue/max_of_sub_arrays.go diff --git a/queue/maximum_of_sub_arrays_test.go b/queue/max_of_sub_arrays_test.go similarity index 71% rename from queue/maximum_of_sub_arrays_test.go rename to queue/max_of_sub_arrays_test.go index 18458cf..8acdbf8 100644 --- a/queue/maximum_of_sub_arrays_test.go +++ b/queue/max_of_sub_arrays_test.go @@ -10,9 +10,13 @@ TestMaxOfKLengthSubArrays tests solution(s) with the following signature and pro func MaxOfKLengthSubArrays(numbers []int, k int) ([]int, error) -Given a set an array of numbers like {1,2,3,4,5} and a number k like 2 return the maximum in -each k-lengthed sub array. e.g. {2,3,4,5} corresponding to the max in each set of the sub -arrays {{1,2},{2,3},{3,4},{4,5}}. +Given a slice of numbers and an integer k return a slice containing the maximum in each k-sized +sub-array (sub-slice) of the input. + +For example given {1,2,3,4,5} and k=2, return {2,3,4,5} because: + +* Sub-arrays of the input with length 2 are {{1,2},{2,3},{3,4},{4,5}} +* The maximum in each of the sub-arrays is {2,3,4,5} */ func TestMaxOfKLengthSubArrays(t *testing.T) { tests := []struct { diff --git a/queue/is_tree_symmetrical.go b/queue/symmetrical_binary_tree.go similarity index 100% rename from queue/is_tree_symmetrical.go rename to queue/symmetrical_binary_tree.go diff --git a/queue/is_tree_symmetrical_test.go b/queue/symmetrical_binary_tree_test.go similarity index 100% rename from queue/is_tree_symmetrical_test.go rename to queue/symmetrical_binary_tree_test.go diff --git a/recursion/README.md b/recursion/README.md index b413891..66da4dc 100644 --- a/recursion/README.md +++ b/recursion/README.md @@ -64,5 +64,5 @@ Recursion finds practical application within a range of algorithms, including [D * [Climbing Stairs](./climbing_stairs_test.go), [Solution](./climbing_stairs.go) * [Exponentiation](./exponentiation_test.go), [Solution](./exponentiation.go) * [Multiplication](./multiplication_test.go), [Solution](./multiplication.go) -* [Regular Expressions Matching](./regular_expressions_test.go), [Solution](./regular_expressions.go) +* [Regular Expression Matching](./regular_expression_test.go), [Solution](./regular_expression.go) * [Expression Operators](./expression_operators_test.go), [Solution](./expression_operators.go) diff --git a/recursion/regular_expressions.go b/recursion/regular_expression.go similarity index 100% rename from recursion/regular_expressions.go rename to recursion/regular_expression.go diff --git a/recursion/regular_expressions_test.go b/recursion/regular_expression_test.go similarity index 100% rename from recursion/regular_expressions_test.go rename to recursion/regular_expression_test.go diff --git a/strings/README.md b/strings/README.md index 561b86c..d457d32 100644 --- a/strings/README.md +++ b/strings/README.md @@ -45,6 +45,6 @@ Strings store words, characters, sentences, etc. * [Look and Tell](./look_and_tell_test.go), [Solution](./look_and_tell.go) * [In Memory Database](./in_memory_database_test.go), [Solution](./in_memory_database.go) * [Number in English](./number_in_english_test.go), [Solution](./number_in_english.go) -* [Reverse Vowels In a String](./reverse_vowels_test.go), [Solution](./reverse_vowels.go) +* [Reverse Vowels in a String](./reverse_vowels_test.go), [Solution](./reverse_vowels.go) * [Roman Numerals](./roman_numerals_test.go), [Solution](./roman_numerals.go) * [Longest Substring of Two Unique Characters](./longest_substring_test.go), [Solution](./longest_substring.go) diff --git a/tree/README.md b/tree/README.md index 1ed2b14..0cf5a72 100644 --- a/tree/README.md +++ b/tree/README.md @@ -75,4 +75,4 @@ Trees, such as Binary Search Trees (BSTs), offer O(Log n) time complexity for se * [Sorted Array to Balanced BST](./sorted_array_to_balanced_bsd_test.go), [Solution](./sorted_array_to_balanced_bsd.go) * [Traverse Binary Tree](./traverse_binary_tree_test.go), [Solution](./traverse_binary_tree.go) * [Reverse Binary Tree](./reverse_binary_tree_test.go), [Solution](./reverse_binary_tree.go) -* [Implement Autocomplete](./auto_complete_test.go), [Solution](./auto_complete.go) +* [Autocompletion](./autocompletion_test.go), [Solution](./autocompletion.go) diff --git a/tree/auto_complete.go b/tree/autocompletion.go similarity index 91% rename from tree/auto_complete.go rename to tree/autocompletion.go index b2c0f95..00f287c 100644 --- a/tree/auto_complete.go +++ b/tree/autocompletion.go @@ -14,8 +14,8 @@ type ( } ) -// AutoComplete solves the problem in O(n) time and O(n) space. -func (t *trie) AutoComplete(word string) []string { +// Autocompletion solves the problem in O(n) time and O(n) space. +func (t *trie) Autocompletion(word string) []string { output := []string{} current := t.root for i := range len(word) { diff --git a/tree/auto_complete_test.go b/tree/autocompletion_test.go similarity index 90% rename from tree/auto_complete_test.go rename to tree/autocompletion_test.go index fb143cd..eb5bd72 100644 --- a/tree/auto_complete_test.go +++ b/tree/autocompletion_test.go @@ -6,7 +6,7 @@ import ( ) /* -TestAutoComplete tests solution(s) with the following signature and problem description: +TestAutocompletion tests solution(s) with the following signature and problem description: func (t *trie) AutoComplete(word string) []string @@ -14,7 +14,7 @@ Given a word like "car" and a dictionary like {"car","caravan","card","carpet"," return autocomplete suggestions where the given word is the prefix of a dictionary word like {"avan","d","pet"}. */ -func TestAutoComplete(t *testing.T) { +func TestAutocompletion(t *testing.T) { tests := []struct { input string dict []string @@ -36,7 +36,7 @@ func TestAutoComplete(t *testing.T) { for i, test := range tests { trie := newTrie(test.dict) - got := trie.AutoComplete(test.input) + got := trie.Autocompletion(test.input) if !slices.Equal(got, test.suggestions) { t.Fatalf("Failed test case #%d. Want %q got %q", i, test.suggestions, got) } From 78b6f3eb9263c63931728d30d7bdc1f910e1bc52 Mon Sep 17 00:00:00 2001 From: Ryan Maleki Date: Mon, 20 Jan 2025 10:10:34 -0800 Subject: [PATCH 3/4] =?UTF-8?q?Use=20unicode=20=E2=80=A6=20instead=20of=20?= =?UTF-8?q?3=20dots=20and=20more=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- array/equal_sum_subarrays_test.go | 2 +- array/find_duplicate_in_array_test.go | 2 +- bit/addition_without_operators_test.go | 2 +- bit/max_without_comparison_operators_test.go | 2 +- graph/README.md | 2 +- queue/max_of_sub_arrays_test.go | 2 +- strings/longest_dictionary_word.go | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 031fd50..469df26 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design * [Sudoku](./backtracking/sudoku_test.go) * [N Queens](./backtracking/n_queens_test.go) * [Graphs](./graph/README.md) - * [Iteratively Implement BFS and DFS](./graph/iterative_traversal_test.go) + * [Iteratively BFS and DFS](./graph/iterative_traversal_test.go) * [DAG Graphs](./graph/is_dag_test.go) * [Topological Sort](./graph/topological_sort_test.go) * [Employee Headcount](./graph/employee_headcount_test.go) diff --git a/array/equal_sum_subarrays_test.go b/array/equal_sum_subarrays_test.go index 19a4cbb..40daa19 100644 --- a/array/equal_sum_subarrays_test.go +++ b/array/equal_sum_subarrays_test.go @@ -13,7 +13,7 @@ TestEqualSumSubArrays tests solution(s) with the following signature and problem Given an list of integers A, return two sub-arrays with equal sums without changing the order of the elements in the list. -For example given {1,7,3,5, return {1,7} and {3,5} because 1+7 = 3+5 = 8. +For example given {1,7,3,5}, return {1,7} and {3,5} because 1+7 = 3+5 = 8. */ func TestEqualSumSubArrays(t *testing.T) { tests := []struct { diff --git a/array/find_duplicate_in_array_test.go b/array/find_duplicate_in_array_test.go index ab3dcb5..6c1605b 100644 --- a/array/find_duplicate_in_array_test.go +++ b/array/find_duplicate_in_array_test.go @@ -7,7 +7,7 @@ TestFindDuplicate tests solution(s) with the following signature and problem des FindDuplicate(list []int) int -Given an unsorted slice of n positive integers like {3,2,1,4,5,4,...,n} where each number is smaller +Given an unsorted slice of n positive integers like {3,2,1,4,5,4,…,n} where each number is smaller than n and there is at most one duplicate, return the duplicate value like 4. */ func TestFindDuplicate(t *testing.T) { diff --git a/bit/addition_without_operators_test.go b/bit/addition_without_operators_test.go index 02c3bd2..502b5d1 100644 --- a/bit/addition_without_operators_test.go +++ b/bit/addition_without_operators_test.go @@ -7,7 +7,7 @@ TestAdditionWithoutArithmeticOperators tests solution(s) with the following sign func Add(x, y int) int -Add x by y, two integers without using any arithmetic operators such as {+,-,/,*,++,--,+=,...} +Add x by y, two integers without using any arithmetic operators such as {+,-,/,*,++,--,+=,…}. */ func TestAdditionWithoutArithmeticOperators(t *testing.T) { tests := []struct { diff --git a/bit/max_without_comparison_operators_test.go b/bit/max_without_comparison_operators_test.go index 9afcf7d..2f087d0 100644 --- a/bit/max_without_comparison_operators_test.go +++ b/bit/max_without_comparison_operators_test.go @@ -8,7 +8,7 @@ TestMax tests solution(s) with the following signature and problem description: func Max(x, y int) int Write max, a function that returns the largest of two numbers without using a -any of the comparison operators such as {if, switch,...}. +any of the comparison operators such as {if, switch,…}. */ func TestMax(t *testing.T) { tests := []struct { diff --git a/graph/README.md b/graph/README.md index 856ba0b..9a8db54 100644 --- a/graph/README.md +++ b/graph/README.md @@ -269,7 +269,7 @@ Graph algorithms find extensive usage in addressing real-world challenges, inclu ## Rehearsal -* [Iteratively Implement BFS and DFS](./iterative_traversal_test.go), [Solution](./iterative_traversal.go) +* [Iteratively BFS and DFS](./iterative_traversal_test.go), [Solution](./iterative_traversal.go) * [DAG Graphs](./is_dag_test.go), [Solution](./is_dag.go) * [Topological Sort](./topological_sort_test.go), [Solution](./topological_sort.go) * [Employee Headcount](./employee_headcount_test.go), [Solution](./employee_headcount.go) diff --git a/queue/max_of_sub_arrays_test.go b/queue/max_of_sub_arrays_test.go index 8acdbf8..a96bc9e 100644 --- a/queue/max_of_sub_arrays_test.go +++ b/queue/max_of_sub_arrays_test.go @@ -10,7 +10,7 @@ TestMaxOfKLengthSubArrays tests solution(s) with the following signature and pro func MaxOfKLengthSubArrays(numbers []int, k int) ([]int, error) -Given a slice of numbers and an integer k return a slice containing the maximum in each k-sized +Given a slice of numbers and an integer k, return a slice containing the maximum in each k-sized sub-array (sub-slice) of the input. For example given {1,2,3,4,5} and k=2, return {2,3,4,5} because: diff --git a/strings/longest_dictionary_word.go b/strings/longest_dictionary_word.go index 12f7da1..760f02f 100644 --- a/strings/longest_dictionary_word.go +++ b/strings/longest_dictionary_word.go @@ -17,7 +17,7 @@ func LongestDictionaryWordContainingKey(key string, dic []string) string { } // hash turns a string into a number -// the output for "abc", "acb", "cba" and etc... are all the same. +// the output for "abc", "acb", "cba" and etc… are all the same. func hash(s string) rune { var res rune for _, w := range s { From e8a9e243278b285975777ee9160531dda0e96bc4 Mon Sep 17 00:00:00 2001 From: Ryan Maleki Date: Mon, 20 Jan 2025 11:32:32 -0800 Subject: [PATCH 4/4] lint fix --- queue/max_of_sub_arrays_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queue/max_of_sub_arrays_test.go b/queue/max_of_sub_arrays_test.go index a96bc9e..713c2f0 100644 --- a/queue/max_of_sub_arrays_test.go +++ b/queue/max_of_sub_arrays_test.go @@ -16,7 +16,7 @@ sub-array (sub-slice) of the input. For example given {1,2,3,4,5} and k=2, return {2,3,4,5} because: * Sub-arrays of the input with length 2 are {{1,2},{2,3},{3,4},{4,5}} -* The maximum in each of the sub-arrays is {2,3,4,5} +* The maximum in each of the sub-arrays is {2,3,4,5}. */ func TestMaxOfKLengthSubArrays(t *testing.T) { tests := []struct {