Skip to content

Commit

Permalink
merge problem descriptions for arrays (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
spring1843 committed Jul 8, 2023
1 parent f941072 commit 131f827
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 44 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ 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 Numbers](./array/add_two_numbers_test.go)
* [Add Two Numbers](./array/add_two_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)
* [Equal Sum Sub-arrays](./array/equal_sum_subarrays_test.go)
* [Rotate K Steps](./array/rotate_k_steps_test.go)
* [Rotate K Times](./array/rotate_k_steps_test.go)
* [Bubble Sort](./array/bubble_sort_test.go)
* [Strings](./strings/README.md)
* [The longest Dictionary Word Containing Key](./strings/longest_dictionary_word_test.go)
Expand Down
39 changes: 8 additions & 31 deletions array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,11 @@ Arrays are used wherever sequential data or more than one piece of data is neede

## Rehearsal

### Reverse Array In-place

Given an array of integers, a start index, and an end index, reverse the integers in the array in-place without using any extra memory. [Solution](reverse_inplace.go), [Tests](reverse_inplace_test.go)

### Add Numbers

Given two numbers as an array like [2,9] and [9,9,9] return the sum of the numbers they represent like [1,0,2,8], because 29+999=1028. [Solution](add_two_numbers.go), [Tests](add_two_numbers_test.go)

### Find Duplicate in Array

Given an array of integers (1,2,...,n), find a duplicate number in O(n) time. [Solution](find_duplicate_in_array.go), [Tests](find_duplicate_in_array_test.go)

### Zero Sum Triplets

Given an array of numbers like `{1, 2, -4, 6, 3}` returns unique triplets from the numbers with sum that equals zero like `{-4, 1, 3}`. [Solution](zero_sum_triplets.go), [Tests](zero_sum_triplets_test.go)

### Product of All Other Elements

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. [Solution](product_of_all_other_elements.go), [Tests](product_of_all_other_elements_test.go)

### Equal Sum Sub-arrays

Given an array of integers A, return two sub-arrays with equal sums without changing the order of elements. . [Solution](equal_sum_subarrays.go), [Tests](equal_sum_subarrays_test.go)

### Rotate K Steps

Given an array of integers and a number k, rotate the array k times. [Solution](rotate_k_steps.go), [Tests](rotate_k_steps_test.go)

### Bubble Sort

Given an array of unsorted integers, sort the array using the Bubble Sort algorithm, where each element is repeatedly compared with the next element and swapped if needed. [Solution](bubble_sort.go), [Tests](bubble_sort_test.go)
* [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)
* [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)
* [Equal Sum Sub-arrays](./equal_sum_subarrays_test.go), [Solution](./equal_sum_subarrays.go)
* [Rotate K Times](./rotate_k_steps_test.go), [Solution](./rotate_k_steps.go)
* [Bubble Sort](./bubble_sort_test.go), [Solution](bubble_sort.go)
5 changes: 3 additions & 2 deletions array/add_two_numbers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ TestAddTwoNumbers tests solution(s) with the following signature and problem des
AddTwoNumbers(num1, num2 []int) []int
Adds two numbers which are represented as an array and returns the results
In the same format. For example [2,5], and [3,5] would add up to[6,0] because 25 + 35 = 60.
Given two numbers as an array like [2,9] and [9,9,9] return the sum of the numbers they
represent like [1,0,2,8], because 29+999=1028.
*/
func TestAddTwoNumbers(t *testing.T) {
tests := []struct {
Expand All @@ -21,6 +21,7 @@ func TestAddTwoNumbers(t *testing.T) {
{[]int{1}, []int{0}, []int{1}},
{[]int{1}, []int{1}, []int{2}},
{[]int{1}, []int{9}, []int{1, 0}},
{[]int{2, 5}, []int{3, 5}, []int{6, 0}},
{[]int{2, 9}, []int{9, 9, 9}, []int{1, 0, 2, 8}},
{[]int{9, 9, 9}, []int{9, 9, 9}, []int{1, 9, 9, 8}},
}
Expand Down
4 changes: 3 additions & 1 deletion array/bubble_sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ TestBubbleSort tests solution(s) with the following signature and problem descri
BubbleSort(input []int)
Implements the Bubble Sort algorithm.
Given an array of unsorted integers, sort the array using the Bubble Sort algorithm.
The algorithm should be in-place, meaning it should not create a new array and it should
work by swapping elements in the array until it is sorted.
*/
func TestBubbleSort(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions array/equal_sum_subarrays_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ TestEqualSumSubArrays tests solution(s) with the following signature and problem
func EqualSubArrays(list []int) [][]int {
Given a list of integers returns two sub arrays that have equal sums without changing the
order of the items in the list.
Given an list of integers A, return two sub-arrays with equal sums without changing the
order of the elements in the list.
*/
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 @@ -9,7 +9,7 @@ TestFindDuplicate tests solution(s) with the following signature and problem des
FindDuplicate(list []int) int
Finds the duplicate in a list of integers (1,n).
Given a list of integers (1,2,...,n), find a duplicate number in O(n) time.
*/
func TestFindDuplicate(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions array/product_of_all_other_elements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ TestProductOfAllOtherElements tests solution(s) with the following signature and
ProductOfAllOtherElements(list []int) []int
Returns an array such that n[i] is the product of all elements of the array except n[i].
Division operation is not allowed.
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.
*/
func TestProductOfAllOtherElements(t *testing.T) {
tests := []struct {
Expand Down
3 changes: 2 additions & 1 deletion array/reverse_inplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ TestReverseInPlace tests solution(s) with the following signature and problem de
ReverseInPlace(list []int, start, end int)
Reverses parts of the array in place.
Given an array of integers, a start index, and an end index, reverse the integers in the
array in-place without using any extra memory.
*/
func TestReverseInPlace(t *testing.T) {
tests := []struct {
Expand Down
2 changes: 1 addition & 1 deletion array/rotate_k_steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TestRotateKSteps tests solution(s) with the following signature and problem desc
RotateKSteps(list []int, k int)
Rotates a given array k steps.
Given an list of integers and a number k, rotate the array k times.
*/
func TestRotateKSteps(t *testing.T) {
tests := []struct {
Expand Down
3 changes: 2 additions & 1 deletion array/zero_sum_triplets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ TestZeroSumTriplets tests solution(s) with the following signature and problem d
ZeroSumTriplets(list []int) [][]int
Finds all triplets in a list that sum to zero.
Given an array of numbers like {1, 2, -4, 6, 3} returns unique triplets from the numbers
with sum that equals zero like {-4, 1, 3}.
*/
func TestZeroSumTriplets(t *testing.T) {
tests := []struct {
Expand Down

0 comments on commit 131f827

Please sign in to comment.