puzzle

package
v0.0.0-...-1763559 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2024 License: MIT Imports: 8 Imported by: 0

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

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 Readlink(linkPath string) string

Readlink normalizes a path string to remove extra '.' and '..'.

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

func Translate

func Translate(number uint64) string

Translate returns Enlish words of a number.

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