MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / SelectK

Function SelectK

search/selectk.go:3–8  ·  view source on GitHub ↗
(array []int, k int)

Source from the content-addressed store, hash-verified

1package search
2
3func SelectK(array []int, k int) (int, error) {
4 if k > len(array) {
5 return -1, ErrNotFound
6 }
7 return selectK(array, 0, len(array), len(array)-k), nil
8}
9
10// search the element which index is idx
11func selectK(array []int, l, r, idx int) int {

Callers 2

TestSelectKFunction · 0.85
BenchmarkSelectKFunction · 0.85

Calls 1

selectKFunction · 0.85

Tested by 2

TestSelectKFunction · 0.68
BenchmarkSelectKFunction · 0.68