Skip to content

Commit d22b3b9

Browse files
committed
Update min size subarray sum doc
1 parent 527742f commit d22b3b9

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ List of Programs related to data structures and algorithms
4848
5. Max sum subarray: [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/5.maxSumSubarray/maxSumSubarray.js)
4949
[Playground](https://livecodes.io/?console=open&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/5.maxSumSubarray/maxSumSubarray.js) [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/5.maxSumSubarray/maxSumSubarray.md)
5050

51-
6. Minimum size subarray sum: [JavaScript](https://livecodes.io/?console=open&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/minimumSizeSubarraySum/minSizeSubarraySum.js) [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/minimumSizeSubarraySum/minSizeSubarraySum.md)
51+
6. Minimum size subarray sum: [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/6.minimumSizeSubarraySum/minSizeSubarraySum.js)
52+
[Playground](https://livecodes.io/?console=open&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/6.minimumSizeSubarraySum/minSizeSubarraySum.js) [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/6.minimumSizeSubarraySum/minSizeSubarraySum.md)
5253

5354
7. Sort Colors: [JavaScript](https://livecodes.io/?console=open&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/sortColors/sortColors.js) [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/array/sortColors/sortColors.md)
5455

src/java1/algorithms/array/minimumSizeSubarraySum/MinimumSizeSubarraySum.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
**Algorithmic Steps**
1+
**Description:**
2+
Given an array of positive integers `nums` and a positive integer `target`, return the minimal length of a contiguous
3+
subarray whose sum is greater than or equal to `target`. If there is no such subarray, return `0` instead.
4+
5+
### Examples:
6+
#### Example 1:
7+
8+
Input: target = 7, nums = [2,4,1,2,4,3]
9+
Output: 2
10+
11+
#### Example 2:
12+
Input: target = 15, nums = [2, 2, 2, 2, 2]
13+
Output: 0
14+
15+
**Algorithmic Steps:**
216
This problem is solved with the help of sliding window approach without using any special data structure. The algorithmic approach can be summarized as follows:
317

418
1. Initialize left and right pointers to 0, to keep track of the substring window boundaries.

src/javascript/algorithms/array/minimumSizeSubarraySum/minSizeSubarraySum.md src/javascript/algorithms/array/6.minimumSizeSubarraySum/minSizeSubarraySum.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
**Algorithmic Steps**
1+
**Description:**
2+
Given an array of positive integers `nums` and a positive integer `target`, return the minimal length of a contiguous
3+
subarray whose sum is greater than or equal to `target`. If there is no such subarray, return `0` instead.
4+
5+
### Examples:
6+
#### Example 1:
7+
8+
Input: target = 7, nums = [2,4,1,2,4,3]
9+
Output: 2
10+
11+
#### Example 2:
12+
Input: target = 15, nums = [2, 2, 2, 2, 2]
13+
Output: 0
14+
15+
**Algorithmic Steps:**
216
This problem is solved with the help of sliding window approach without using any special data structure. The algorithmic approach can be summarized as follows:
317

418
1. Initialize left and right pointers to 0, to keep track of the substring window boundaries.
519

620
2. Initialize total variable to 0, to store the sum of the subarray values to meet the target criteria.
721

8-
3. Initialize result variable to infinity to indicate that there is no subarray to meet target value.
22+
3. Initialize result variable to max integer value to indicate that there is no subarray to meet target value.
923

1024
4. Iterate over the input array using right pointer until the end of the string.
1125

@@ -17,7 +31,7 @@ This problem is solved with the help of sliding window approach without using an
1731

1832
8. Repeat steps 4–7 until the right pointer reaches the end of the array.
1933

20-
9. Return 0 if the result is still an infinity which indicates no valid subarray otherwise return the calculated minimum subarray value.
34+
9. Return 0 if the result is still a maximum integer which indicates no valid subarray otherwise return the calculated minimum subarray value.
2135

2236
**Time and Space complexity:**
2337
This algorithm has a time complexity of O(n) because we are traversing the array only twice at max. Since it doens't require any datastructure, the space complexity will be O(1).

0 commit comments

Comments
 (0)