Skip to content

Problem title cleanup #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -112,8 +112,8 @@ 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)
* [Is Graph a DAG](./graph/is_dag_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)
* [Remove Invalid Parentheses](./graph/remove_invalid_parentheses_test.go)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions array/add_two_numbers.go → array/add_slice_of_numbers.go
Original file line number Diff line number Diff line change
@@ -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-- {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ 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

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) {
func TestAddSliceOfTwoNumbers(t *testing.T) {
tests := []struct {
num1, num2, sum []int
}{
Expand All @@ -26,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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion array/equal_sum_subarrays_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion array/find_duplicate_in_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion array/product_of_all_other_elements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion array/reverse_inplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
9 changes: 5 additions & 4 deletions array/rotate_k_steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions bit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions bit/addition_without_operators.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions bit/addition_without_operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion dp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ 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)
* [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)
* [Remove Invalid Parentheses](./remove_invalid_parentheses_test.go), [Solution](./remove_invalid_parentheses.go)
Expand Down
4 changes: 2 additions & 2 deletions greedy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions greedy/max_number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion heap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
File renamed without changes.
File renamed without changes.
Loading
Loading