A subarray is a contiguous portion
of an array.
If array = [1, 2, 3, 4, 5], then [2, 3, 4] is a subarray, but [1, 3,
5] is NOT.
Key property: No gaps! All elements must be
consecutive.
🟢 Click to select START index (S)
Start Index (S)
-
End Index (E)
-
✓ Valid Subarray
1
2
3
4
5
[2, 3, 4] - Contiguous!
✗ NOT a Subarray
1
2
3
4
5
[1, 3, 5] - Has gaps!
✓ Single Element
1
2
3
4
5
[3] - Valid subarray!
✓ Full Array
1
2
3
4
5
[1,2,3,4,5] - Also valid!
📊 Subarray Count Formula
For an array of size n:
Total subarrays = n × (n + 1) / 2 This counts all possible contiguous segments!