- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find number of K-Length sublists whose average is greater or same as target in python

Suppose we have a list nums, and two additional values k and target, we have to find the number of sublists whose size is k and its average value ≥ target.

So, if the input is like nums = [1, 10, 5, 6, 7] k = 3 target = 6, then the output will be 2, as the sublist [1, 10, 7] has average value of 6 and [10, 5, 6] has average of 7.

To solve this, we will follow these steps:

- target := target * k
- sum := 0, ans := 0
- for each index i and number n in nums, do
- if i >= k, then
- sum := sum - nums[i - k]

- sum := sum + n
- if i >=(k - 1) , then
- if sum >= target, then
- ans := ans + 1

- if sum >= target, then

- if i >= k, then
- return ans

Let us see the following implementation to get better understanding:

## Example Code

class Solution: def solve(self, nums, k, target): target *= k sum = 0 ans = 0 for i, n in enumerate(nums): if i >= k: sum -= nums[i - k] sum += n if i >= (k - 1): if sum >= target: ans += 1 return ans ob = Solution() nums = [1, 10, 5, 6, 7] k = 3 target = 6 print(ob.solve(nums, k, target))

## Input

[1, 10, 5, 6, 7], 3, 6

## Output

2

- Related Articles
- Program to find number of sublists whose sum is given target in python
- Program to find minimum number of subsequence whose concatenation is same as target in python
- Program to check we can find four elements whose sum is same as k or not in Python
- Program to find number of unique subsequences same as target in C++
- Program to find maximum length of k ribbons of same length in Python
- C++ code to find greater number whose factor is k
- Program to find sum of k non-overlapping sublists whose sum is maximum in C++
- Program to find number of sublists that contains exactly k different words in Python
- Program to find largest average of sublist whose size at least k in Python
- Program to split lists into strictly increasing sublists of size greater than k in Python
- Program to find number of sublists with sum k in a binary list in Python
- Program to find max values of sublists of size k in Python
- Python – Average of digit greater than K
- Program to count number of sublists with exactly k unique elements in Python
- Program to find array of length k from given array whose unfairness is minimum in python

Advertisements