feat: top k frequent

This commit is contained in:
2025-12-15 22:39:37 -05:00
parent da48abc0d1
commit 7fdf6a520f
2 changed files with 109 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
package top_k_frequent_elements_test
import (
"testing"
"git.maximhutz.com/practice/pkg/top_k_frequent_elements"
"github.com/stretchr/testify/assert"
)
func Test1(t *testing.T) {
assert.Equal(t, []int{1, 2}, top_k_frequent_elements.TopKFrequent([]int{1, 1, 1, 2, 2, 3}, 2))
}
func Test2(t *testing.T) {
assert.Equal(t, []int{1}, top_k_frequent_elements.TopKFrequent([]int{1}, 1))
}
func Test3(t *testing.T) {
assert.Equal(t, []int{1, 4}, top_k_frequent_elements.TopKFrequent([]int{1, 4, 1, 4, 1, 4, 3, 1, 3, 4}, 2))
}