Documentation ¶
Overview ¶
Package puzzle :: array.go
Package puzzle :: duplicate.go
Package puzzle :: eval.go
Package puzzle :: expr.go
Package puzzle :: integer.go
Package puzzle :: matrix.go
Package puzzle :: median.go
Package puzzle :: nimgame.go
Package puzzle :: queens.go
Package puzzle :: readlink.go
Package puzzle :: regex.go
Package puzzle :: string.go
Package puzzle :: sum.go
Index ¶
- func CheckExpression(expr string) bool
- func CheckMatchedPair(s, begin, close string) (bool, error)
- func Find2ndLargest(x []int) int
- func FindAjacent1s(matrix [][]int) []string
- func FindAvailableSpot(numbers []int) int
- func FindDuplicate(inputs []int) int
- func FindDuplicates(inputs []int) ([]int, error)
- func FindMatchedSum(inputs []int, sum int) (int, int)
- func FindMedian(stream []int) float64
- func GetAllCases(s string) []string
- func GetLongestSubstringLength(input string) (int, string)
- func GetLongestSubstringUTF8(input string) (int, string, int, int)
- func GetLongestUniqueSubstring(input string) string
- func GetMostFrequentRune(input string) (rune, int)
- func Readlink(linkPath string) string
- func SumMaxtrixDiagonal(matrix [][]int) (int64, int64)
- func Translate(number uint64) string
- type BasicRegex
- type Eval
- type Queens
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckExpression ¶
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 ¶
CheckMatchedPair determines if a given pair, e.g. parenthesis or bracket, in a string all have valid matches
func Find2ndLargest ¶
Find2ndLargest returns the second largest in an array
func FindAjacent1s ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
GetAllCases returns all variations of upper and lower cases
func GetLongestSubstringLength ¶
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 ¶
GetLongestSubstringUTF8 solves the following problem: Given a string, find the longest substring without repeating characters. Note: This is to support UTF-8
func GetLongestUniqueSubstring ¶
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 ¶
GetMostFrequentRune returns the rune and count of the most appearance
func SumMaxtrixDiagonal ¶
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
type Queens ¶
type Queens [][]bool
Queens type
func PlaceQueens ¶
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