Java: Find the smallest length of a contiguous subarray of which the sum is greater than or equal to specified value
70. Find smallest length subarray with sum >= specified value
Write a Java program to find the smallest length of a contiguous subarray of which the sum is greater than or equal to a specified value. Return 0 instead.
Example:
Input :
nums = {1, 2, 3, 4, 6}
Output:
Minimum length of a contiguous subarray of which the sum is 8, 2
Sample Solution:
Java Code:
Sample Output:
Original array: [1, 2, 3, 4, 6] Minimum length of a contiguous subarray of which the sum is 8, 2
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to find the largest length of a contiguous subarray with a sum less than or equal to a given value.
- Write a Java program to find the maximum sum of a contiguous subarray of length k.
- Write a Java program to find the total number of subarrays with a sum greater than a given value.
- Write a Java program to find the shortest subarray whose sum is a multiple of a given number.
Go to:
PREV : Find minimum subarray sum of specified size.
NEXT : Find largest number from a list of non-negative integers.
Java Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.