8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 869aae8 commit 4a88cfbCopy full SHA for 4a88cfb
01/main.go
@@ -30,14 +30,21 @@ func main() {
30
31
func countLargerThanPrevious(vals []int) int {
32
var count int
33
- var last int = vals[0]
34
- for i := 1; i < len(vals); i++ {
35
- if vals[i] <= last {
36
- last = vals[i]
37
- continue
+ var topWindow int = vals[0] + vals[1] + vals[2]
+
+ // top window = A,B,C
+ //
+ // On each check
38
+ // W2 = W1 - v[i-3] + v[i]
39
+ // if W2 > W1 count++
40
+ // W1 = W2
41
42
+ for i := 3; i < len(vals); i++ {
43
+ bottomWindow := topWindow - vals[i-3] + vals[i]
44
+ if bottomWindow > topWindow {
45
+ count++
46
}
- count++
47
+ topWindow = bottomWindow
48
49
return count
50
0 commit comments