MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / dietPlanPerformance

Function dietPlanPerformance

diet_plan_performance_1176/solution.go:3–23  ·  view source on GitHub ↗
(calories []int, k int, lower int, upper int)

Source from the content-addressed store, hash-verified

1package diet_plan_performance_1176
2
3func dietPlanPerformance(calories []int, k int, lower int, upper int) int {
4 start := 0
5 end := k - 1
6 t := 0
7 for i := start; i <= end; i++ {
8 t += calories[i]
9 }
10
11 points := getPointsForT(t, lower, upper)
12
13 for end < len(calories)-1 {
14 t = t - calories[start]
15 start++
16 end++
17 t = t + calories[end]
18
19 points += getPointsForT(t, lower, upper)
20 }
21
22 return points
23}
24
25func getPointsForT(t, lower, upper int) int {
26 if t < lower {

Callers 1

Test_dietPlanPerformanceFunction · 0.85

Calls 1

getPointsForTFunction · 0.85

Tested by 1

Test_dietPlanPerformanceFunction · 0.68