Skip to content

move rehersal problem descriptions to test files #84

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 3 commits into from
Jul 8, 2023
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
2 changes: 1 addition & 1 deletion array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Arrays are used wherever sequential data or more than one piece of data is neede
* [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))
* [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)
Expand Down
22 changes: 5 additions & 17 deletions backtracking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,8 @@ Backtracking is widely used to solve board games and is often employed by comput

## Permutations

Given a list of integers like `{1,2}`, produce all possible combinations like `{1,2},{2,1}`. [Solution](permutations.go), [Tests](permutations_test.go)

### Generate Parenthesis

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)

### Phone Letter Combinations

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)

### Sudoku

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)

### N Queens

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)
* [Permutations](permutations_test.go), [Solution](permutations.go)
* [Generate Parenthesis](generate_parenthesis_test.go), [Solution](generate_parenthesis.go)
* [Phone Letter Combinations](phone_letter_combinations_test.go), [Solution](phone_letter_combinations.go)
* [Sudoku](sudoku_test.go), [Solution](sudoku.go)
* [N Queens](n_queens_test.go), [Solution](n_queens.go)
3 changes: 2 additions & 1 deletion backtracking/generate_parenthesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ TestGenerateParenthesis tests solution(s) with the following signature and probl

GenerateParenthesis(n int) []string

Returns all possible variation of n pairs of valid parenthesis.
Given an integer n produce all valid variations of arranging
n pair of parenthesis. e.g. for `2` it should return `()()` and `(())`.
*/
func TestGenerateParenthesis(t *testing.T) {
tests := []struct {
Expand Down
5 changes: 3 additions & 2 deletions backtracking/n_queens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ TestNQueens tests solution(s) with the following signature and problem descripti

func NQueens(n int) []Chessboard

Returns possible solutions to the n-queen puzzle in an n x n chessboard
where n queens are placed on the chessboard such that none attacks another.
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.
*/
func TestNQueens(t *testing.T) {
tests := []struct {
Expand Down
3 changes: 1 addition & 2 deletions backtracking/permutations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ TestPermutations tests solution(s) with the following signature and problem desc

func Permutations(input []int) [][]int {

Intakes a list of numbers and returns all possible permutations of their orders
For example for {1,2} it would return {1,2}, {2,1}.
Given a list of integers like {1,2}, produce all possible combinations like {1,2},{2,1}.
*/
func TestPermutations(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions backtracking/phone_letter_combinations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ TestPhoneLetterCombinations tests solution(s) with the following signature and p

func PhoneLetterCombinations(digits string) []string

Intakes the digits from 2 to 9 that represent phone buttons
and returns all possible combinations of letters that could be generated from those.
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.
*/
func TestPhoneLetterCombinations(t *testing.T) {
tests := []struct {
Expand Down
7 changes: 4 additions & 3 deletions backtracking/sudoku_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ TestSudoku tests solution(s) with the following signature and problem descriptio

func Sudoku(board [][]int) bool {

Solves a given partially filled or empty 9x9 Sudoku board by placing integers
between 1 and 9 in empty spot designated by 0 such that In each row, column, and
3x3 sub square the values are unique.
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.
*/
func TestSudoku(t *testing.T) {
tests := []boardAndSolution{
Expand Down
24 changes: 5 additions & 19 deletions bit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,8 @@ Negation can be used to invert a set of flags or to find the two's complement of

## Rehearsal

### Division without multiplication or division operators

Divide x by y, two integers without using the built-in `/` or `*` operators. [Solution](division_without_operators.go), [Tests](division_without_operators_test.go)

### Middle without division

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)

### Addition without using plus (+) or any other arithmetic operators

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)

### Maximum without if conditions

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)

### Oddly Repeated Number

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)
* [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)
* [Maximum without if conditions](max_function_without_conditions_test.go), [Solution](max_function_without_conditions.go)
* [Oddly Repeated Number](oddly_repeated_number_test.go), [Solution](oddly_repeated_number.go)
2 changes: 1 addition & 1 deletion bit/addition_without_operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TestAdd tests solution(s) with the following signature and problem description:

func Add(x, y int) int

Adds to numbers without using any arithmetic operators.
Add x by y, two integers without using the built-in + or any other arithmetic operators.
*/
func TestAdd(t *testing.T) {
tests := []struct {
Expand Down
2 changes: 1 addition & 1 deletion bit/division_without_operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TestDivision tests solution(s) with the following signature and problem descript

func Divide(x, y int) int {

Divides two numbers without using division or multiplication symbols.
Divide x by y, two integers without using the built-in `/` or `*` operators.
*/
func TestDivision(t *testing.T) {
tests := []struct {
Expand Down
3 changes: 2 additions & 1 deletion bit/max_function_without_conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ TestMax tests solution(s) with the following signature and problem description:

func Max(x, y int) int

Returns the maximum of two numbers without using if conditions.
Write max, a function that returns the largest of two numbers without using a
comparison or if conditions.
*/
func TestMax(t *testing.T) {
tests := []struct {
Expand Down
3 changes: 2 additions & 1 deletion bit/middle_without_division_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ TestMiddleWithoutDivision tests solution(s) with the following signature and pro

func MiddleWithoutDivision(min, max int)

Finds the middle integer between two integers.
Given two integers min and max like `1` and `5`, return an integer like `3` that is in
the middle of the two.
*/
func TestMiddleWithoutDivision(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions bit/oddly_repeated_number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ TestOddlyRepeatedNumber tests solution(s) with the following signature and probl

func OddlyRepeatedNumber(list []int) int

Repeated number finds an element in a given array that is repeated an
odd number of times.
Given an array of integers that are all repeated an even number of times except one,
find the oddly repeated element.
*/
func TestOddlyRepeatedNumber(t *testing.T) {
tests := []struct {
Expand Down
24 changes: 5 additions & 19 deletions dnc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,8 @@ DNC algorithms are suitable for solving problems that can be divided into smalle

## Rehearsal

### Binary Search

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)

### Square Root with Binary Search

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)

### Rate Limit

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)

### Towers of Hanoi

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)

### Merge Sort

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)
* [Binary Search](binary_search_test.go), [Solution](binary_search.go)
* [Square Root with Binary Search](square_root_test.go), [Solution](square_root.go)
* [Rate Limit](rate_limit_test.go), [Solution](rate_limit.go)
* [Towers of Hanoi](towers_of_hanoi_test.go), [Solution](towers_of_hanoi.go)
* [Merge Sort](merge_sort_test.go), [Solution](merge_sort.go)
9 changes: 7 additions & 2 deletions dnc/binary_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ TestBinarySearch tests solution(s) with the following signature and problem desc

func BinarySearch(list []int, search int) int

Finds the index a given number in an ordered slice of sorted integers
using Binary Search.
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 using Binary Search.

In Binary Search we start with the middle element of the set and compare it with
the target. If the target is greater than the middle element we search the right
half of the set, otherwise we search the left half of the set. We repeat this
process until we find the target or we exhaust the set.
*/
func TestBinarySearch(t *testing.T) {
tests := []struct {
Expand Down
2 changes: 1 addition & 1 deletion dnc/merge_sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TestMergeSort tests solution(s) with the following signature and problem descrip

func MergeSort(list []int) []int

Sorts a list of integers using Merge Sort.
Given a list of integers like {3,1,2}, return a sorted set like {1,2,3} using Merge Sort.
*/
func TestMergeSort(t *testing.T) {
tests := []struct {
Expand Down
8 changes: 4 additions & 4 deletions dnc/rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
/*
TestRateLimiter tests solution(s) with the following signature and problem description:

IsAllowed(limitPerSecond int) bool
func IsAllowed(limitPerSecond int) bool

Returns wether or not the caller is allowed to perform an action. The caller is allowed
to perform an action if the number of actions performed in the last second is less than
or equal to limitPerSecond.
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.
*/
func TestRateLimiter(t *testing.T) {
tests := []struct {
Expand Down
3 changes: 2 additions & 1 deletion dnc/square_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ TestSquareRoot tests solution(s) with the following signature and problem descri

func SquareRoot(number, precision int) float64

Uses Binary search to find the square root of a number up to a precision point.
Given a number and precision, return the square root of the number using the binary
search algorithm.
*/
func TestSquareRoot(t *testing.T) {
tests := []struct {
Expand Down
9 changes: 4 additions & 5 deletions dnc/towers_of_hanoi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ TestTowerOfHanoi tests solution(s) with the following signature and problem desc

func TowerOfHanoi(n, start, end int) [][2]int {

Returns the moves it takes to move all disks from start to end with respect
to the rules of the Tower of Hanoi game where:
n is the number of disks stacked on top of each other
heavier disks can never be placed on a lighter disk
There are 3 towers, all disks are initially places at the start tower.
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.
*/
func TestTowerOfHanoi(t *testing.T) {
tests := []struct {
Expand Down
24 changes: 5 additions & 19 deletions dp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,8 @@ DP is well-suited for tackling an array of complex problems, including those in

## Rehearsal

### Rod Cutting

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)

### Sum Up to Number

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)

### House Robber

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)

### Minimum Deletion to Make a Palindrome

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)

### Word Distance

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)
* [Rod Cutting](rod_cutting_test.go), [Solution](rod_cutting.go)
* [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).
* [Minimum Deletion to Make a Palindrome](minimum_deletion_to_make_palindrome_test.go), [Solution](minimum_deletion_to_make_palindrome.go)
* [Word Distance](word_distance_test.go), [Solution](word_distance.go.go)
6 changes: 3 additions & 3 deletions dp/house_robber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ TestMaxHouseRobber tests solution(s) with the following signature and problem de

func MaxHouseRobber(wealth []int) int

given an array representing the amount of wealth inside a house
and given that the robber can steal only non-consecutive houses
returns the maximum amount of wealth the robber can steal.
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.
*/
func TestMaxHouseRobber(t *testing.T) {
tests := []struct {
Expand Down
3 changes: 2 additions & 1 deletion dp/minimum_deletion_to_make_palindrome_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ TestMinimumDeletionsToMakePalindrome tests solution(s) with the following signat

func MinimumDeletionsToMakePalindrome(input string) int

Returns how many deletions can be done in the input string to make it a palindrome.
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) {
tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions dp/rod_cutting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ TestRodCutting tests solution(s) with the following signature and problem descri

CutRod(prices []int, n int) int

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
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.
*/
Expand Down
5 changes: 3 additions & 2 deletions dp/sum_up_to_integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ TestSumUpToInteger tests solution(s) with the following signature and problem de

SumUpToInteger(numbers []int, sum int) bool {

When given a list of integers and a sum, returns true if any combination of the integers
sums up to the sum.
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.
*/
func TestSumUpToInteger(t *testing.T) {
tests := []struct {
Expand Down
6 changes: 4 additions & 2 deletions dp/word_distance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ TestWordDistance tests solution(s) with the following signature and problem desc

func WordDistance(input1, input2 string) int

Returns how many character modifications (insert, delete, edit) can
be done on the first input string so that it becomes equal to the second string.
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. In this case, the answer is 2.
*/
func TestWordDistance(t *testing.T) {
tests := []struct {
Expand All @@ -25,6 +26,7 @@ func TestWordDistance(t *testing.T) {
{"ab", "ac", 1},
{"ab", "dc", 2},
{"ab", "dcd", 3},
{"abc", "abcde", 2},
{"abcdef", "abcde", 1},
{"gabcdef", "abcde", 2},
}
Expand Down
Loading