The number of all possible subarrays of an array of size N is N * (N + 1)/2.
- How do I find all the subarrays of an array?
- How do you calculate Subarrays?
- How do you find the number of contiguous Subarrays?
How do I find all the subarrays of an array?
We can use substr function to find the all possible sub array.
How do you calculate Subarrays?
Naive Approach: The simplest approach to solve this problem is to generate all possible subarrays from the given array and for each subarray, check if its product is even or not. If found to be true for any subarray, increase count. Finally, print the count obtained.
How do you find the number of contiguous Subarrays?
To calculate the number of subarrays that include the element at the ith index, we simply subtract the number of subarrays not including the element at the ith index from the total number of ways.