puzzle

package
v0.0.0-...-e40056c Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2017 License: MIT Imports: 7 Imported by: 0

README

Coding Questions


## Array - [find adjacent 1s in an integer matrix](matrix.go) - [find duplicated number in an array contains n numbers ranging from 0 to n-2](duplicate.go) | [test](duplicate_test.go) - [find the best meetup point for all given points](../interview/meetup.go) | [test](../interview/meetup_test.go) - [find the closest k points to a given point](../interview/meetup.go) - [find the maximum sum of sequence in an integer array](../interview/sequence.go) | [test](../interview/sequence_test.go) - [find the median in an integer array](median.go) | [test](median_test.go) - [find the first available parking spot](array.go) | [test](array_test.go) | [solution](../pkg/parking) - [find the second largest in an array](integer.go) | [test](integer_test.go) - [find the single integer in an array where all other elements appear twice](singleNumber.js) - [place N queens on NxN chessboard so that they can't attack each other](queens.go) | [test](queens_test.go) | [java](queens.java) - [sum of matrix diagonal items](matrix.go)
## Mathematics - [buying stock at best price](../pkg/stock) | [test](../pkg/stock/stock_test.go) - [fibonacci](../ds/mathEx/fibo.go) | [test](../ds/mathEx/fibo_test.go)
## String - [basic regular expression](regex.go) | [test](regex_test.go) | [java](regex.java) | [js](regex.js) - [compress/decompress string](../ds/str/str.go) | [test](../ds/str/str_test.go) - [convert string to integer](../demo/integer.go) | [test](../demo/integer_test.go) - [find palindrome in string](palindrome.go) | [test](palindrome_test.go) - [eval mathematical expressions](eval.go) (2-stack without parentheses grouping) | [test]() - [find the longest subsequence in a string](../interview/sequence.go) | [test](../interview/sequence_test.go) - [find the number of occurrences of the most frequent substring in a string](../interview/string.go) | [test](../interview/string_test.go) - [justify a line of string text](../interview/justify.go) | [test](../interview/justify_test.go) - [search trie](../ds/trie/trie.go) | [test](../ds/trie/trie_test.go) - [reverse string](../ds/str/reverse.go) | [test](../ds/str/reverse_test.go) - [reverse words](../ds/str/reverseWords.go) | [test](../ds/str/reverseWords_test.go) - [sort array](../ds/str/sort.go) | [test](../ds/str/sort_test.go)
## Others - [chan](../demo/chan.go) | [test](../demo/chan_test.go) - [nim game](nimgame.go) - [singleton](../demo/singleton.go) - [testing template](../demo/foo.go) | [test](../demo/foo_test.go) - [trie](../ds/trie/trie.go) | [test](../ds/trie/trie_test.go)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckExpression

func CheckExpression(expr string) bool

CheckExpression checks if an expression has proper openings and closings of e.g. `()`, `[]`, and `{}`. TODO: supporting any string pairs, e.g. "<head>": "</head>"

func CheckMatchedPair

func CheckMatchedPair(s, begin, close string) (bool, error)

CheckMatchedPair determines if a given pair, e.g. parenthesis or bracket, in a string all have valid matches

func Find2ndLargest

func Find2ndLargest(x []int) int

Find2ndLargest returns the second largest in an array

func FindAjacent1s

func FindAjacent1s(matrix [][]int) []string

FindAjacent1s returns all coordinates "x,y" of adjacent 1s, where the position has adjacent 1s horizontally or vertically, from a matrix contains only 0s and 1s

func FindAvailableSpot

func FindAvailableSpot(numbers []int) int

FindAvailableSpot returns first available spot from an array of occupied parking spot numbers in a parking garage which has parking spots 0..N (N could be infinite) note: in a design for real parking garage,

a) the available spots should be thread-safe to support concurrency
b) or to update first available info at any time before assigned

func FindDuplicate

func FindDuplicate(inputs []int) int

FindDuplicate looks up for one duplicated number in an integer array contains n numbers ranging from 0 to n-2. Note: There is exactly one number duplicated in the array.

func FindDuplicates

func FindDuplicates(inputs []int) ([]int, error)

FindDuplicates returns a set of duplicated numbers in an integer array contains n numbers ranging from 0 to n-1. Note: There could be multiple duplicates in the array.

func FindMatchedSum

func FindMatchedSum(inputs []int, sum int) (int, int)

FindMatchedSum returns index in input array of two items match to the sum. See: https://leetcode.com/problems/two-sum/ Problems: Given an array of integers, find indices of the two numbers

such that they add up to a specific sum

Keywords: array, hash, sum

func FindMedian

func FindMedian(stream []int) float64

FindMedian func Find the median (the middle value in an ordered integer list). For even size of the list, the median is the mean of the two middle value. See https://leetcode.com/problems/find-median-from-data-stream/

func GetAllCases

func GetAllCases(s string) []string

GetAllCases returns all variations of upper and lower cases

func GetLongestSubstringLength

func GetLongestSubstringLength(input string) (int, string)

GetLongestSubstringLength solves the following problem: Given a string, find the longest non-repeating substring length. Note: assuming all input are ASCII characters Tags: hash table, map, two pointers, string

func GetLongestSubstringUTF8

func GetLongestSubstringUTF8(input string) (int, string, int, int)

GetLongestSubstringUTF8 solves the following problem: Given a string, find the longest substring without repeating characters. Note: This is to support UTF-8

func GetLongestUniqueSubstring

func GetLongestUniqueSubstring(input string) string

GetLongestUniqueSubstring solves the following problem: Given a string, find the longest substring without repeating characters. For example:

"abc" from "aaabcabcbb", and the length is 3
"o" from "oooooo", and the length of 1

func GetMostFrequentRune

func GetMostFrequentRune(input string) (rune, int)

GetMostFrequentRune returns the rune and count of the most appearance

func SumMaxtrixDiagonal

func SumMaxtrixDiagonal(matrix [][]int) (int64, int64)

SumMaxtrixDiagonal returns both diagonal sum of up-left to down-right and up-right to down-left

Types

type BasicRegex

type BasicRegex struct {
	// contains filtered or unexported fields
}

BasicRegex struct

func NewBasicRegex

func NewBasicRegex(input, regex string) *BasicRegex

NewBasicRegex returns a pointer to a new BasicRegex object

func (*BasicRegex) IsMatch

func (br *BasicRegex) IsMatch() bool

IsMatch tests if the input matches regex

type Eval

type Eval struct {
	// contains filtered or unexported fields
}

Eval struct is a string stack implementation

func NewEval

func NewEval(e string) *Eval

NewEval return a new instance of Eval struct

type Queens

type Queens [][]bool

Queens type

func PlaceQueens

func PlaceQueens(n int) []Queens

PlaceQueens func Place N queens on NxN chessboard so that no two of them attack each other See https://developers.google.com/optimization/puzzles/queens

func (*Queens) String

func (q *Queens) String() string

String func for Queens

Jump to

Keyboard shortcuts

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