Skip to content

Commit bf92606

Browse files
authored
move rehersal problem descriptions to test files (#84)
1 parent 9386d1e commit bf92606

File tree

89 files changed

+252
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+252
-410
lines changed

array/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Arrays are used wherever sequential data or more than one piece of data is neede
8989
* [Reverse Array In-place](./reverse_inplace_test.go), [Solution](./reverse_inplace.go)
9090
* [Add Two Numbers](./add_two_numbers_test.go), [Solution](./add_two_numbers.go)
9191
* [Find Duplicate in Array](./find_duplicate_in_array_test.go), [Solution](./find_duplicate_in_array.go)
92-
* [Zero Sum Triplets](./zero_sum_triplets_test.go), [Solution]((./zero_sum_triplets.go))
92+
* [Zero Sum Triplets](./zero_sum_triplets_test.go), [Solution](./zero_sum_triplets.go)
9393
* [Product of All Other Elements](./product_of_all_other_elements_test.go), [Solution](./product_of_all_other_elements.go)
9494
* [Equal Sum Sub-arrays](./equal_sum_subarrays_test.go), [Solution](./equal_sum_subarrays.go)
9595
* [Rotate K Times](./rotate_k_steps_test.go), [Solution](./rotate_k_steps.go)

backtracking/README.md

+5-17
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,8 @@ Backtracking is widely used to solve board games and is often employed by comput
2727

2828
## Permutations
2929

30-
Given a list of integers like `{1,2}`, produce all possible combinations like `{1,2},{2,1}`. [Solution](permutations.go), [Tests](permutations_test.go)
31-
32-
### Generate Parenthesis
33-
34-
Write a function that intakes an integer n, and produces all valid variations of arranging n pair of parenthesis. e.g. for `2` it should return `()()` and `(())`. [Solution](generate_parenthesis.go), [Tests](generate_parenthesis_test.go)
35-
36-
### Phone Letter Combinations
37-
38-
Write a function that intakes a string of digits from 2 to 9 inclusive and returns all possible combinations of letters that could be generated from those. For example for input `2` it should return `abc`. [Solution](phone_letter_combinations.go), [Tests](phone_letter_combinations_test.go)
39-
40-
### Sudoku
41-
42-
Given a partially filled 9x9 grid with integers from 1 to 9 representing a Sudoku board and 0 representing an empty slot that needs to be filled, write a function that solves the board such that the values in each row, column and each of the 9 3x3 sub-grids are unique. [Solution](sudoku.go), [Tests](sudoku_test.go)
43-
44-
### N Queens
45-
46-
Given an integer n representing an n by n chessboard, return all possible arrangements of placing n queens on the chessboard such that the queens do not attack each other. [Solution](n_queens.go), [Tests](n_queens_test.go)
30+
* [Permutations](permutations_test.go), [Solution](permutations.go)
31+
* [Generate Parenthesis](generate_parenthesis_test.go), [Solution](generate_parenthesis.go)
32+
* [Phone Letter Combinations](phone_letter_combinations_test.go), [Solution](phone_letter_combinations.go)
33+
* [Sudoku](sudoku_test.go), [Solution](sudoku.go)
34+
* [N Queens](n_queens_test.go), [Solution](n_queens.go)

backtracking/generate_parenthesis_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ TestGenerateParenthesis tests solution(s) with the following signature and probl
1111
1212
GenerateParenthesis(n int) []string
1313
14-
Returns all possible variation of n pairs of valid parenthesis.
14+
Given an integer n produce all valid variations of arranging
15+
n pair of parenthesis. e.g. for `2` it should return `()()` and `(())`.
1516
*/
1617
func TestGenerateParenthesis(t *testing.T) {
1718
tests := []struct {

backtracking/n_queens_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ TestNQueens tests solution(s) with the following signature and problem descripti
1010
1111
func NQueens(n int) []Chessboard
1212
13-
Returns possible solutions to the n-queen puzzle in an n x n chessboard
14-
where n queens are placed on the chessboard such that none attacks another.
13+
Given an integer n representing an n by n chessboard, return all possible
14+
arrangements of placing n queens on the chessboard such that the queens do not
15+
attack each other.
1516
*/
1617
func TestNQueens(t *testing.T) {
1718
tests := []struct {

backtracking/permutations_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ TestPermutations tests solution(s) with the following signature and problem desc
1010
1111
func Permutations(input []int) [][]int {
1212
13-
Intakes a list of numbers and returns all possible permutations of their orders
14-
For example for {1,2} it would return {1,2}, {2,1}.
13+
Given a list of integers like {1,2}, produce all possible combinations like {1,2},{2,1}.
1514
*/
1615
func TestPermutations(t *testing.T) {
1716
tests := []struct {

backtracking/phone_letter_combinations_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ TestPhoneLetterCombinations tests solution(s) with the following signature and p
1111
1212
func PhoneLetterCombinations(digits string) []string
1313
14-
Intakes the digits from 2 to 9 that represent phone buttons
15-
and returns all possible combinations of letters that could be generated from those.
14+
Intakes a string of digits from 2 to 9 inclusive and returns all possible combinations of letters
15+
that could be generated from those. For example for input 2 it should return abc.
1616
*/
1717
func TestPhoneLetterCombinations(t *testing.T) {
1818
tests := []struct {

backtracking/sudoku_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ TestSudoku tests solution(s) with the following signature and problem descriptio
1515
1616
func Sudoku(board [][]int) bool {
1717
18-
Solves a given partially filled or empty 9x9 Sudoku board by placing integers
19-
between 1 and 9 in empty spot designated by 0 such that In each row, column, and
20-
3x3 sub square the values are unique.
18+
Given a partially filled 9x9 grid with integers from 1 to 9 representing a Sudoku
19+
board and 0 representing an empty slot that needs to be filled, write a function
20+
that solves the board such that the values in each row, column and each of
21+
the 9 3x3 sub-grids are unique.
2122
*/
2223
func TestSudoku(t *testing.T) {
2324
tests := []boardAndSolution{

bit/README.md

+5-19
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,8 @@ Negation can be used to invert a set of flags or to find the two's complement of
107107

108108
## Rehearsal
109109

110-
### Division without multiplication or division operators
111-
112-
Divide x by y, two integers without using the built-in `/` or `*` operators. [Solution](division_without_operators.go), [Tests](division_without_operators_test.go)
113-
114-
### Middle without division
115-
116-
Given two integers min and max like `1` and `5`, return an integer like `3` that is in the middle of the two. [Solution](middle_without_division.go), [Tests](middle_without_division_test.go)
117-
118-
### Addition without using plus (+) or any other arithmetic operators
119-
120-
Add x by y, two integers without using the built-in + or any other arithmetic operators. [Solution](addition_without_operators.go), [Tests](addition_without_operators_test.go)
121-
122-
### Maximum without if conditions
123-
124-
Write max, a function that returns the largest of two numbers without using a comparison or if conditions. [Solution](max_function_without_conditions.go), [Tests](max_function_without_conditions_test.go)
125-
126-
### Oddly Repeated Number
127-
128-
Given an array of integers that are all repeated an even number of times except one, find the oddly repeated element. [Solution](oddly_repeated_number.go), [Tests](oddly_repeated_number_test.go)
110+
* [Division without multiplication or division operators](division_without_operators_test.go), [Solution](division_without_operators.go)
111+
* [Middle without division](middle_without_division_test.go), [Solution](middle_without_division.go)
112+
* [Addition without using plus (+) or any other arithmetic operators](addition_without_operators_test.go), [Solution](addition_without_operators.go)
113+
* [Maximum without if conditions](max_function_without_conditions_test.go), [Solution](max_function_without_conditions.go)
114+
* [Oddly Repeated Number](oddly_repeated_number_test.go), [Solution](oddly_repeated_number.go)

bit/addition_without_operators_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TestAdd tests solution(s) with the following signature and problem description:
77
88
func Add(x, y int) int
99
10-
Adds to numbers without using any arithmetic operators.
10+
Add x by y, two integers without using the built-in + or any other arithmetic operators.
1111
*/
1212
func TestAdd(t *testing.T) {
1313
tests := []struct {

bit/division_without_operators_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TestDivision tests solution(s) with the following signature and problem descript
77
88
func Divide(x, y int) int {
99
10-
Divides two numbers without using division or multiplication symbols.
10+
Divide x by y, two integers without using the built-in `/` or `*` operators.
1111
*/
1212
func TestDivision(t *testing.T) {
1313
tests := []struct {

bit/max_function_without_conditions_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ TestMax tests solution(s) with the following signature and problem description:
77
88
func Max(x, y int) int
99
10-
Returns the maximum of two numbers without using if conditions.
10+
Write max, a function that returns the largest of two numbers without using a
11+
comparison or if conditions.
1112
*/
1213
func TestMax(t *testing.T) {
1314
tests := []struct {

bit/middle_without_division_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ TestMiddleWithoutDivision tests solution(s) with the following signature and pro
77
88
func MiddleWithoutDivision(min, max int)
99
10-
Finds the middle integer between two integers.
10+
Given two integers min and max like `1` and `5`, return an integer like `3` that is in
11+
the middle of the two.
1112
*/
1213
func TestMiddleWithoutDivision(t *testing.T) {
1314
tests := []struct {

bit/oddly_repeated_number_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ TestOddlyRepeatedNumber tests solution(s) with the following signature and probl
99
1010
func OddlyRepeatedNumber(list []int) int
1111
12-
Repeated number finds an element in a given array that is repeated an
13-
odd number of times.
12+
Given an array of integers that are all repeated an even number of times except one,
13+
find the oddly repeated element.
1414
*/
1515
func TestOddlyRepeatedNumber(t *testing.T) {
1616
tests := []struct {

dnc/README.md

+5-19
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,8 @@ DNC algorithms are suitable for solving problems that can be divided into smalle
9292

9393
## Rehearsal
9494

95-
### Binary Search
96-
97-
Given a sorted set of integers like `{1,2,3,4,6}`, and a target int like `4` find its position in the set like `3`. [Solution](binary_search.go) [Test](binary_search_test.go)
98-
99-
### Square Root with Binary Search
100-
101-
Given a number and precision, return the square root of the number using the binary search algorithm. [Solution](square_root.go) [Test](square_root_test.go)
102-
103-
### Rate Limit
104-
105-
Given a number of allowed requests calls per second (calls/time) write an IsAllowed function which returns false if the request should be rate limited because it exceeds the limit and true if the request should be allowed. [Solution](rate_limit.go) [Test](rate_limit_test.go)
106-
107-
### Towers of Hanoi
108-
109-
Given n, number of disks, and start and end tower, return the moves it takes to move all disks from start to end tower. The disks are stacked on top of each other with the lightest being on top and heaviest being in the bottom. A heavier disk cannot be placed on a lighter disk. You can move one disk at a time. [Solution](towers_of_hanoi.go) [Test](towers_of_hanoi_test.go)
110-
111-
### Merge Sort
112-
113-
Given a list of integers like `{3,1,2}`, return a sorted set like `{1,2,3}` using Merge Sort. [Solution](merge_sort.go) [Test](merge_sort_test.go)
95+
* [Binary Search](binary_search_test.go), [Solution](binary_search.go)
96+
* [Square Root with Binary Search](square_root_test.go), [Solution](square_root.go)
97+
* [Rate Limit](rate_limit_test.go), [Solution](rate_limit.go)
98+
* [Towers of Hanoi](towers_of_hanoi_test.go), [Solution](towers_of_hanoi.go)
99+
* [Merge Sort](merge_sort_test.go), [Solution](merge_sort.go)

dnc/binary_search_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ TestBinarySearch tests solution(s) with the following signature and problem desc
99
1010
func BinarySearch(list []int, search int) int
1111
12-
Finds the index a given number in an ordered slice of sorted integers
13-
using Binary Search.
12+
Given a sorted set of integers like {1,2,3,4,6}, and a target int like 4 find its
13+
position in the set like 3 using Binary Search.
14+
15+
In Binary Search we start with the middle element of the set and compare it with
16+
the target. If the target is greater than the middle element we search the right
17+
half of the set, otherwise we search the left half of the set. We repeat this
18+
process until we find the target or we exhaust the set.
1419
*/
1520
func TestBinarySearch(t *testing.T) {
1621
tests := []struct {

dnc/merge_sort_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TestMergeSort tests solution(s) with the following signature and problem descrip
1010
1111
func MergeSort(list []int) []int
1212
13-
Sorts a list of integers using Merge Sort.
13+
Given a list of integers like {3,1,2}, return a sorted set like {1,2,3} using Merge Sort.
1414
*/
1515
func TestMergeSort(t *testing.T) {
1616
tests := []struct {

dnc/rate_limit_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
/*
1010
TestRateLimiter tests solution(s) with the following signature and problem description:
1111
12-
IsAllowed(limitPerSecond int) bool
12+
func IsAllowed(limitPerSecond int) bool
1313
14-
Returns wether or not the caller is allowed to perform an action. The caller is allowed
15-
to perform an action if the number of actions performed in the last second is less than
16-
or equal to limitPerSecond.
14+
Given a number of allowed requests calls per second (calls/time) write an IsAllowed
15+
function which returns false if the request should be rate limited because it exceeds the
16+
limit and true if the request should be allowed.
1717
*/
1818
func TestRateLimiter(t *testing.T) {
1919
tests := []struct {

dnc/square_root_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ TestSquareRoot tests solution(s) with the following signature and problem descri
1010
1111
func SquareRoot(number, precision int) float64
1212
13-
Uses Binary search to find the square root of a number up to a precision point.
13+
Given a number and precision, return the square root of the number using the binary
14+
search algorithm.
1415
*/
1516
func TestSquareRoot(t *testing.T) {
1617
tests := []struct {

dnc/towers_of_hanoi_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ TestTowerOfHanoi tests solution(s) with the following signature and problem desc
1010
1111
func TowerOfHanoi(n, start, end int) [][2]int {
1212
13-
Returns the moves it takes to move all disks from start to end with respect
14-
to the rules of the Tower of Hanoi game where:
15-
n is the number of disks stacked on top of each other
16-
heavier disks can never be placed on a lighter disk
17-
There are 3 towers, all disks are initially places at the start tower.
13+
Given n, number of disks, and start and end tower, return the moves it takes to move all
14+
disks from start to end tower. The disks are stacked on top of each other with the
15+
lightest being on top and heaviest being in the bottom. A heavier disk cannot be placed
16+
on a lighter disk. You can move one disk at a time.
1817
*/
1918
func TestTowerOfHanoi(t *testing.T) {
2019
tests := []struct {

dp/README.md

+5-19
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,8 @@ DP is well-suited for tackling an array of complex problems, including those in
2929

3030
## Rehearsal
3131

32-
### Rod Cutting
33-
34-
Given a list containing price a table such as `{1,5,8,9,10}` indicating the price of a rod of a given length (1 inch rod is $1, 2 inch rod is $5, 5 inch rod is $10) and number n like 3, indicating the length of a given rod, calculate maximum revenue that can be earned by cutting the rod and selling the pieces when cutting is free. [Solution](rod_cutting.go), [Tests](rod_cutting_test.go)
35-
36-
### Sum Up to Number
37-
38-
Given a set of positive integers like `{1,2,3,4,5}` and an integer like `7` write a function that returns true if there are two numbers in the list that sum up to the given integer and false otherwise. [Solution](sum_up_to_integer.go), [Tests](sum_up_to_integer_test.go)
39-
40-
### House Robber
41-
42-
Given an array representing the amount of wealth inside houses like `{1,2,3,4}` return the maximum wealth the robber can steal like `6` with the condition that he is not allowed to rob two consecutive houses. [Solution](house_robber.go), [Tests](house_robber_test.go)
43-
44-
### Minimum Deletion to Make a Palindrome
45-
46-
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`). [Solution](minimum_deletion_to_make_palindrome.go), [Tests](minimum_deletion_to_make_palindrome_test.go)
47-
48-
### Word Distance
49-
50-
Given a string like `abc`, and another string like `abcde` return how many character modifications (insert, delete, edit) have to be done on the first string to become identical to the second string. [Solution](word_distance.go.go), [Tests](word_distance.go_test.go)
32+
* [Rod Cutting](rod_cutting_test.go), [Solution](rod_cutting.go)
33+
* [Sum Up to Number](sum_up_to_integer_test.go), [Solution](sum_up_to_integer.go)
34+
* [House Robber](house_robber_test.go), [Solution](house_robber.go).
35+
* [Minimum Deletion to Make a Palindrome](minimum_deletion_to_make_palindrome_test.go), [Solution](minimum_deletion_to_make_palindrome.go)
36+
* [Word Distance](word_distance_test.go), [Solution](word_distance.go.go)

dp/house_robber_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ TestMaxHouseRobber tests solution(s) with the following signature and problem de
99
1010
func MaxHouseRobber(wealth []int) int
1111
12-
given an array representing the amount of wealth inside a house
13-
and given that the robber can steal only non-consecutive houses
14-
returns the maximum amount of wealth the robber can steal.
12+
Given an array representing the amount of wealth inside houses like {1,2,3,4} return the
13+
maximum wealth the robber can steal like `6` with the condition that he is not allowed to
14+
rob two consecutive houses.
1515
*/
1616
func TestMaxHouseRobber(t *testing.T) {
1717
tests := []struct {

dp/minimum_deletion_to_make_palindrome_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ TestMinimumDeletionsToMakePalindrome tests solution(s) with the following signat
99
1010
func MinimumDeletionsToMakePalindrome(input string) int
1111
12-
Returns how many deletions can be done in the input string to make it a palindrome.
12+
Given a string like abccb return the minimum number of character deletions that can be done on the string
13+
to make it a palindrome like 1 (by removing a, we will have bccb).
1314
*/
1415
func TestMinimumDeletionsToMakePalindrome(t *testing.T) {
1516
tests := []struct {

dp/rod_cutting_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ TestRodCutting tests solution(s) with the following signature and problem descri
1010
1111
CutRod(prices []int, n int) int
1212
13-
Given a list containing price a table such as {1,5,8,9,10} indicating the price of a
14-
rod of a given length (1 inch rod is $1, 2 inch rod is $5, 5 inch rod is $10) and
13+
Given a list containing price a table such as {1,5,8,9,10} indicating the price of
14+
a rod of a given length (1 inch rod is $1, 2 inch rod is $5, 5 inch rod is $10) and
1515
number n like 3, indicating the length of a given rod, calculate maximum revenue that
1616
can be earned by cutting the rod and selling the pieces when cutting is free.
1717
*/

dp/sum_up_to_integer_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ TestSumUpToInteger tests solution(s) with the following signature and problem de
99
1010
SumUpToInteger(numbers []int, sum int) bool {
1111
12-
When given a list of integers and a sum, returns true if any combination of the integers
13-
sums up to the sum.
12+
Given a set of positive integers like {1,2,3,4,5} and an integer like 7 write a
13+
function that returns true if there are two numbers in the list that sum up to the given
14+
integer and false otherwise.
1415
*/
1516
func TestSumUpToInteger(t *testing.T) {
1617
tests := []struct {

dp/word_distance_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ TestWordDistance tests solution(s) with the following signature and problem desc
99
1010
func WordDistance(input1, input2 string) int
1111
12-
Returns how many character modifications (insert, delete, edit) can
13-
be done on the first input string so that it becomes equal to the second string.
12+
Given a string like abc, and another string like abcde return how many character
13+
modifications (insert, delete, edit) have to be done on the first string to become
14+
identical to the second string. In this case, the answer is 2.
1415
*/
1516
func TestWordDistance(t *testing.T) {
1617
tests := []struct {
@@ -25,6 +26,7 @@ func TestWordDistance(t *testing.T) {
2526
{"ab", "ac", 1},
2627
{"ab", "dc", 2},
2728
{"ab", "dcd", 3},
29+
{"abc", "abcde", 2},
2830
{"abcdef", "abcde", 1},
2931
{"gabcdef", "abcde", 2},
3032
}

0 commit comments

Comments
 (0)