Sliding Window
Sliding Window
Sliding Window
Q1. Given an array of integers arr and two integers k and threshold , return the number of sub-arrays of size k
Example 1:
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively. All
Example 2:
Output: 6
Explanation: The first 6 sub-arrays of size 3 have averages greater than 5. Note that
Q2. The score of an array is defined as the product of its sum and its length.
Given a positive integer array nums and an integer k , return the number of non-empty subarrays of nums
Example 1:
Output: 6
Explanation:
C
Java &
++ + DSA
DSA
Note that subarrays such as [1,4] and [4,3,5] are not considered because their scores are 10
Example 2:
Output: 5
Explanation:
Q3. Given an array of integers nums and an integer k . A continuous subarray is called nice if there are k odd
numbers on it.
Example 1:
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
Example 2:
Output: 0
Example 3:
Output: 16
Note:- Please try to invest time doing the assignments which are necessary to build a strong foundation. Do not
directly Copy Paste using Google or ChatGPT. Please use your brain.
Java
C++ &+ DSA
DSA