Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
SequencePosition finds all sublists of LL that match the pattern of $\{e, \ldots, f\ge 2e\}$, where the dots stand for zero or more other numbers (a BlankNullSequence___). The option Overlaps -> All instructs to return all matches: long ones and short ones, even if they overlap:
SequencePosition[LL, {e_, ___, f_} /; f >= 2 e, Overlaps -> All]
Each one of these matches is returned as a pair of indices, giving the start and end position of the match in the original list LL.
We GroupBy these matches by start position (First) and keep only the end positions (Last); then for each of the found groups we calculate the minimum (Min) of these end positions, which gives us the nearest-to-the-right end position satisfying the pattern constraint:
This output is in the form of an Association. To continue, we Lookup each start position (Range[Length[LL]]) in this association to find the smallest end position. If none is found, return {}:
SequencePosition finds all sublists of LL that match the pattern of $\{e, \ldots, f\ge 2e\}$, where the dots stand for zero or more other numbers (a BlankNullSequence___). The option Overlaps -> All instructs to return all matches: long ones and short ones, even if they overlap:
SequencePosition[LL, {e_, ___, f_} /; f >= 2 e, Overlaps -> All]
Each one of these matches is returned as a pair of indices, giving the start and end position of the match in the original list LL.
We GroupBy these matches by start position (First) and keep only the end positions (Last); then for each of the found groups we calculate the minimum (Min) of these end positions, which gives us the nearest-to-the-right end position satisfying the pattern constraint:
This output is in the form of an Association. To continue, we Lookup each start position (Range[Length[LL]]) in this association to find the smallest end position. If none is found, return {}: