Help us shape the future of Go! Take the 2026 Go Developer Survey

cracking-the-coding-interview-in-go

module
v0.0.0-...-aaef64c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2019 License: MIT

README

Cracking the Coding Interview in Go

I bought Cracking the Coding Interview, 6th Ed. as a refresher and study guide. The book is well worth the price for its succinct organization and strategies and hints toward problem solving.

Seeing someone else's implementation is helpful can be helpful, especially when you get stumped, but to truly benefit from the book, it is absolutely vital to write code yourself.

There is an existing repo, but I have not looked at it. I prefer to attempt to solve the problems on my own using the hints and strategies presented in the book. I have definitely needed to refer to the book's solutions, however, which are written in Java.

I have implemented the solutions as tests using the Go testing package. I start each implementation by writing the test cases that I would like to pass, and then work toward writing the solution.

You can run all or specific tests. Examples:

$ go test -v -timeout 30s ./...

$ go test -v -timeout 30s -run ^TestPartition$ ./chapter-02

I've only just begun, so this is definitely a work in progress.

Directories

Path Synopsis
misc
fibonacci
The fibonacci number of a non-negative integer n is defined as: - for n = 0, return 0 - for n = 1, return 1 - for all other positive integers, return the sum of the fibonacci values for the two preceding integers Examples: 0 => 0 (by definition) 1 => 1 (by definition) 2 => 1 3 => 2 = fib(2) + fib(1) = 1 + 1 4 => 3 = fib(3) + fib(2) = 2 + 1 5 => 5 = fib(4) + fib(3) = 3 + 2 6 => 8 = fib(5) + fib(4) = 5 + 3 7 => 13 = fib(6) + fib(5) = 8 + 5 8 => 21 = fib(7) + fib(6) = 13 + 8 9 => 34 = fib(8) + fib(7) = 21 + 13
The fibonacci number of a non-negative integer n is defined as: - for n = 0, return 0 - for n = 1, return 1 - for all other positive integers, return the sum of the fibonacci values for the two preceding integers Examples: 0 => 0 (by definition) 1 => 1 (by definition) 2 => 1 3 => 2 = fib(2) + fib(1) = 1 + 1 4 => 3 = fib(3) + fib(2) = 2 + 1 5 => 5 = fib(4) + fib(3) = 3 + 2 6 => 8 = fib(5) + fib(4) = 5 + 3 7 => 13 = fib(6) + fib(5) = 8 + 5 8 => 21 = fib(7) + fib(6) = 13 + 8 9 => 34 = fib(8) + fib(7) = 21 + 13
prime
Prime is a whole number n that can only be divided by 1 and itself: - for n = 0, return false - for n = 1, return false - for all other n, return true if its only two factors are 1 and n Examples: 0 => false 1 => false 2 => true 3 => true 4 => false (other factors: 2) 5 => true 6 => false (other factors: 2, 3) 7 => true 8 => false (other factors: 2, 4) 9 => false (other factors: 3) 10 => false (other factors: 2, 5) 11 => true 30 => false (other factors: 2, 3, 5, 6, 10, 15) Note: 2 is the only even number that is prime.
Prime is a whole number n that can only be divided by 1 and itself: - for n = 0, return false - for n = 1, return false - for all other n, return true if its only two factors are 1 and n Examples: 0 => false 1 => false 2 => true 3 => true 4 => false (other factors: 2) 5 => true 6 => false (other factors: 2, 3) 7 => true 8 => false (other factors: 2, 4) 9 => false (other factors: 3) 10 => false (other factors: 2, 5) 11 => true 30 => false (other factors: 2, 3, 5, 6, 10, 15) Note: 2 is the only even number that is prime.
template
Foo is a function that for given input n ...
Foo is a function that for given input n ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL