Hot windows
Inputs
values is a list of 1 to 14 whole numbers, each from 0 to 20. k is a whole number from 1 to the length of values. limit is a whole number from 0 to 60.
Your tasks
- Create a number
countthat starts at 0. - Slide a window of
kneighbouring numbers alongvalues, keeping its sum up to date. - Add 1 to
countfor every window whose sum is at leastlimit. - Complete
countHotWindowsso it returnscount. Return it, do not print it.
Example
With values = [4, 8, 2, 9, 1, 7] and k = 3 and limit = 14, countHotWindows returns 3.
Rules
- There are
len(values) - k + 1windows.
Test data
TEST DATA 1: values is [4, 8, 2, 9, 1, 7], k is 3, limit is 14
TEST DATA 2: values is [5], k is 1, limit is 6
Practice focus
Two pointers and sliding windows: loops that move two positions instead of one. Two pointers and sliding windows turn many quadratic answers into linear ones.