Skip to content

Commit 8ea7e1d

Browse files
authored
Move problem description to test files (#80)
1 parent 983391e commit 8ea7e1d

File tree

154 files changed

+698
-161
lines changed

Some content is hidden

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

154 files changed

+698
-161
lines changed

backtracking/generate_parenthesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package backtracking
22

3-
// GenerateParenthesis returns all possible variation of n pairs of valid parenthesis.
3+
// GenerateParenthesis solves the problem in O(2^n) time and O(n) space.
44
func GenerateParenthesis(n int) []string {
55
return generateParenthesisRecursive([]string{}, "", 0, 0, n)
66
}

backtracking/generate_parenthesis_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import (
66
"testing"
77
)
88

9+
/*
10+
TestGenerateParenthesis tests solution(s) with the following signature and problem description:
11+
12+
GenerateParenthesis(n int) []string
13+
14+
Returns all possible variation of n pairs of valid parenthesis.
15+
*/
916
func TestGenerateParenthesis(t *testing.T) {
1017
tests := []struct {
1118
n int

backtracking/n_queens.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const (
88
// Chessboard represents a chessboard.
99
type Chessboard [][]int
1010

11-
// NQueens returns possible solutions to the n-queen puzzle in an n x n chessboard
12-
// where n queens are placed on the chessboard such that none attacks another.
11+
// NQueens solves the problem in O(n!) time and O(n) space.
1312
func NQueens(n int) []Chessboard {
1413
output := nQueensRecursive(0, n, make([]int, n), make(Chessboard, 0))
1514
return toPrettyChessboard(output, n)

backtracking/n_queens_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import (
55
"testing"
66
)
77

8+
/*
9+
TestNQueens tests solution(s) with the following signature and problem description:
10+
11+
func NQueens(n int) []Chessboard
12+
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.
15+
*/
816
func TestNQueens(t *testing.T) {
917
tests := []struct {
1018
n int

backtracking/permutations.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package backtracking
22

3-
// Permutations intakes a list of numbers and returns all possible permutations of their orders
4-
// For example for {1,2} it would return {1,2}, {2,1}.
3+
// Permutations solves the problem in O(n!) time and O(n) space.
54
func Permutations(input []int) [][]int {
65
permutations := make([][]int, 0)
76
permutationsRecursive(input, 0, &permutations)

backtracking/permutations_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import (
55
"testing"
66
)
77

8+
/*
9+
TestPermutations tests solution(s) with the following signature and problem description:
10+
11+
func Permutations(input []int) [][]int {
12+
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}.
15+
*/
816
func TestPermutations(t *testing.T) {
917
tests := []struct {
1018
nums []int

backtracking/phone_letter_combinations.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ var phone = map[byte]string{
1111
'9': "wxyz",
1212
}
1313

14-
// PhoneLetterCombinations 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+
// PhoneLetterCombinations solves the problem in O(3^n) time and O(3^n) space.
1615
func PhoneLetterCombinations(digits string) []string {
1716
combinations := []string{}
1817
if len(digits) > 0 {

backtracking/phone_letter_combinations_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import (
66
"testing"
77
)
88

9+
/*
10+
TestPhoneLetterCombinations tests solution(s) with the following signature and problem description:
11+
12+
func PhoneLetterCombinations(digits string) []string
13+
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.
16+
*/
917
func TestPhoneLetterCombinations(t *testing.T) {
1018
tests := []struct {
1119
digits string

backtracking/sudoku.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package backtracking
22

3-
// Sudoku solves a given partially filled or empty 9x9 Soduku board by placing
4-
// integers between 1 and 9 in empty spot designated by 0 such that
5-
// In each row, column, and 3x3 sub square the values are unique.
3+
// Sudoku solves the problem in O(9^(n*n)) time and O(n*n) space.
64
func Sudoku(board [][]int) bool {
75
for i := 0; i < len(board); i++ {
86
for j := 0; j < len(board[0]); j++ {

backtracking/sudoku_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ type boardAndSolution struct {
1010
solution [][]int
1111
}
1212

13+
/*
14+
TestSudoku tests solution(s) with the following signature and problem description:
15+
16+
func Sudoku(board [][]int) bool {
17+
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.
21+
*/
1322
func TestSudoku(t *testing.T) {
1423
tests := []boardAndSolution{
1524
testBoard1(),

0 commit comments

Comments
 (0)