Subarray
In [2, 5, 1, 4], a subarray selects one uninterrupted range of positions. Choosing the first and last selected index fixes every value between them.
Does the selection occupy one uninterrupted range?
A subarray is fixed by one left boundary and one right boundary. Sliding windows move those boundaries, while prefix sums answer questions about the range between them.
Substring
A substring applies the same uninterrupted-range rule to a string. In "code", the chosen characters must occupy consecutive indices.
Are the chosen characters consecutive?
The data type changes from an array to a string, but the candidate shape does not. A substring is a contiguous slice.
Subsequence
A subsequence may skip positions. The selected values must still appear in the same relative order as the source.
Do selected values keep their source order?
Skipping positions is allowed, but moving backward is not. Once a value is selected, every later selected value must come from a later source position.
Subset
A subset asks which input elements are chosen, without treating their written order as part of the answer. The chosen positions do not need to be adjacent, and changing the order in which the same elements are written does not create a different subset.
For example, choosing 2 and 1 from [2, 5, 1, 4] gives one subset containing those two values. Writing it as [2, 1] or [1, 2] does not describe two different choices.
Which elements are chosen?
Keeping values in input order gives each subset a consistent representation, but that order is not part of the subset’s identity.
A common generation method decides for each input position whether to include it or skip it.
If the input contains equal values, different input positions may produce identical value lists. The problem statement determines whether those duplicate results must be removed.
| Structure | Must positions be contiguous? | May positions be skipped? | Does selection order affect identity? |
|---|---|---|---|
| Subarray | Yes | No | Yes |
| Substring | Yes | No | Yes |
| Subsequence | No | Yes | Yes |
| Subset | No | Yes | No |
[2, 1, 4] a subsequence of [2, 5, 1, 4] but not a subarray?