Sub arrays
Arrays - Subarrays¶
A subarray is a slice from a contiguous array (i.e., occupy consecutive positions) and inherently maintains the order of elements.
Subarrays are arrays within another array.
- For example, the subarrays of array {1, 2, 3} are {1}, {1, 2}, {1, 2, 3}, {2}, {2, 3}, and {3}.
Note:
- No of Sub arrays for a Array of Size N -
(N*(N+1))/2
- No of Sub arrays of Size K for a Array of Size N -
N-K+1