chapter17

package
v0.0.0-...-45e99ae Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddWithoutPlus

func AddWithoutPlus(a int, b int) (result int)

AddWithoutPlus adds 2 numbers without using the `+` sign

func BestSplit

func BestSplit(dictionary map[string]struct{}, sentence string) string

BestSplit splits a string on dictionary words and returns the best parse.

func ComputeHistogramVolume

func ComputeHistogramVolume(histogram []int) int

ComputeHistogramVolume goes through each bar and compute the volume of water above it. volume of water at the bar =

  	height - min(tallest bar on left, tallest bar on right)
		[where above equation is positive]

Compute the left max in the first sweep, then sweep again to compute the right max, minimum of the bar heights, and the delta

func ComputeSimilarities

func ComputeSimilarities(documents []Document) map[DocPair]float64

ComputeSimilarities computes the similarities between different words in the dictionary

func Count2sInRange

func Count2sInRange(number int) int

Count2sInRange counts the number of 2s in a digit

func FindLongestSubarray

func FindLongestSubarray(array []rune) []rune

FindLongestSubarray returns the longest subarray with equal letters and numbers

func FindMajorityElement

func FindMajorityElement(values []int) int

FindMajorityElement finds an element in a list of elements which repeats more than 50% of the time

func FindMissing

func FindMissing(array []int) int

FindMissing returns the missing item from a list of integers from [0,n]

func GetKthMagicNumber

func GetKthMagicNumber(k int) int

GetKthMagicNumber finds the kth number such that the only prime factors are 3, 5, 7

func GetLongestWord

func GetLongestWord(words []string) string

GetLongestWord returns the longest word in a list made up of sub words.

func MaxMinutesIterative

func MaxMinutesIterative(messages []int) int

MaxMinutesIterative returns the max sequence without skipping

func MaxMinutesRecursive

func MaxMinutesRecursive(messages []int) int

MaxMinutesRecursive returns the max sequence with skipping.

func MissingTwo

func MissingTwo(array []int) []int

MissingTwo returns the 2 missing numbers of the array ordered from 0 to N

func PickMRecursively

func PickMRecursively(original []int, m int) []int

PickMRecursively pics M elements from an array randomly

func SearchAllSubstringsInString

func SearchAllSubstringsInString(big string, smalls []string) map[string][]int

SearchAllSubstringsInString returns all substring in a string

func ShuffleArray

func ShuffleArray(array []int)

ShuffleArray shuffles an array

func SmallestK

func SmallestK(array []int, k int) []int

SmallestK returns the smallest K items in an array

func TransformWord

func TransformWord(dictionary []string, source string, target string) []string

TransformWord shows the path for transforming a word from source to target.

func TrulyMostPopular

func TrulyMostPopular(names map[string]int, synonyms [][]string) map[string]int

TrulyMostPopular returns the most popular name taking into account synonyms

Types

type BitNode

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

BitNode is a node with 2 links

func ConvertTreeToDoublyLinkedList

func ConvertTreeToDoublyLinkedList(node *BitNode) *BitNode

ConvertTreeToDoublyLinkedList converts a list to a circular linked list and then breaks the circular connection

type DocPair

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

DocPair is a pair of documents

type Document

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

Document represents a document of words

type HeightWidth

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

HeightWidth is a struct having height and width

func LongestIncreasingSequence

func LongestIncreasingSequence(items []HeightWidth) []HeightWidth

LongestIncreasingSequence returns the longest way in which items can be stacked on top of each other.

type LocationPair

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

LocationPair represents 2 locations

func FindClosest

func FindClosest(word1, word2 string, locations map[string][]int) *LocationPair

FindClosest finds the closest distance between 2 words in a string

type ParseResult

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

ParseResult stores the result of parsing a string

type Range

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

Range represents a range of numbers from start till small

func ShortestSuperSequence

func ShortestSuperSequence(big, small []int) Range

ShortestSuperSequence returns the shortest sequence of all the elements in `small` in the `big` array

type RunningMedianCalculator

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

RunningMedianCalculator gets the running median for a stream of items

func NewRunningMedianCalculator

func NewRunningMedianCalculator() RunningMedianCalculator

NewRunningMedianCalculator calculates the running median

func (*RunningMedianCalculator) Median

func (calculator *RunningMedianCalculator) Median() float64

Median returns the running median

type SubMatrix

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

SubMatrix represents a sub matrix

func MaxMatrix

func MaxMatrix(matrix [][]int) *SubMatrix

MaxMatrix returns the max sub matrix

type SubSquare

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

SubSquare represents a subsquare from a matrix

func FindSquare

func FindSquare(matrix [][]int) *SubSquare

FindSquare returns the biggest square in the matrix

Jump to

Keyboard shortcuts

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