Maximum Feasible Substring under Pattern Supply
- MFSP is a combinatorial optimization problem that identifies the longest substring of a text meeting a pattern’s frequency (Parikh) constraints.
- It employs a linear-time two-pointer sliding window method which dynamically adjusts the substring to maintain feasibility.
- MFSP generalizes Abelian pattern matching, linking resource-budget interpretations with packing-style optimization in string analysis.
Maximum Feasible Substring under Pattern Supply (MFSP) is a combinatorial optimization problem arising in the context of frequency-based (Abelian/permutation/jumbled) pattern matching. Given a pattern and a text over a general alphabet , MFSP seeks the longest substring of whose symbol counts are bounded, component-wise, by those of . This exact resource-budget interpretation generalizes and connects standard Abelian pattern detection with packing-style primitives, and admits a linear-time solution via a two-pointer feasibility-maintenance algorithm (Shanto et al., 14 Jan 2026).
1. Formal Problem Definition
Let be an alphabet of size . Given a pattern and a text , denote the Parikh vector of a string by
0
for each 1. The pattern's Parikh vector 2 is interpreted as a supply or budget vector.
A substring 3 is feasible if
4
or equivalently,
5
The Maximum Feasible Substring under Pattern Supply (MFSP) asks to find
6
The goal is to output the substring 7, which has the maximum length 8 under the component-wise Parikh budget constraint.
2. Linear-Time Two-Pointer Feasibility Algorithm
The core algorithmic insight is that feasibility under the Parikh budget constraint is monotone under left-shrinkage: when a window 9 becomes infeasible at some 0, increasing 1 can only reduce or restore feasibility. The solution maintains the following:
- 2 for all 3,
- 4 for all 5 (running counts for the current window),
- 6 = the number of 7 for which 8 (violation counter).
For each iteration, after extending the right end 9, the algorithm shrinks 0 while 1, ensuring each window 2 is maximal and feasible. The substring of maximum feasible length is retained.
Pseudocode outline:
02
3. Proof Sketch: Correctness and Complexity
- Feasibility Invariant: After the inner
while (viol > 0), 3 and so 4 is feasible; each counter 5 for all 6. - Window Maximality: For each 7, shrinking 8 continues exactly while feasibility is violated, so 9 is a longest feasible suffix ending at 0.
- Global Optimality: For any optimal substring 1, when 2 the algorithm’s window will include a feasible window of length at least 3; the maximum seen is always retained.
- Time and Space Complexity: Each of pointers 4, 5 is advanced at most 6 times. Array initializations and per-symbol updates are 7. Initialization over 8 is 9; total runtime is 0. Space is 1 for 2, 3, and auxiliary counters.
4. Step-by-Step Example
Given 4 (5, 6) and 7 (8):
| 9 | Added char | 0 change | 1 | Window 2 | Remarks / 3 |
|---|---|---|---|---|---|
| 0 | 'a' | 4 | 0 | 5 | Set 6 |
| 1 | 'b' | 7 | 0 | 8 | Set 9 |
| 2 | 'a' | 0 | 0 | 1 | Set 2 |
| 3 | 'a' | 3 | 1 | shrink 4: 5, 6, resolve violation | No update (tie) |
| 4 | 'c' | 7 | 1 | shrink 8: 9, 0, resolve violation | No update |
| 5 | 'b' | 1 | 0 | 2 | Set 3 |
The returned substring is 4 of length 5, conforming to the Parikh budget 6.
5. Specializations and Connections
- Single-Symbol Cases: For 7 with a single symbol 8 at frequency 9, MFSP reduces to the classic search for the longest run of 0 in 1.
- Alphabet Reduction: If 2 is large but 3 is small, the alphabet can be compressed to a smaller effective size 4 prior to algorithm execution.
- Permutation Matching and Packing: MFSP generalizes permutation matching, which asks whether some substring's Parikh vector exactly matches 5; this variant is handled by maintaining a difference vector and can also be solved in 6 time within this framework.
- Non-overlapping Occurrences: After enumerating all length-7 matches, maximizing the count of disjoint occurrences reduces to the equal-length interval packing problem, solved by left-to-right greedy selection in 8 time.
6. Generalizations and Further Directions
- Approximate and Weighted Variants: MFSP admits relaxation to allow limited violation (e.g., 9), or extension to weighted settings where each symbol is associated with a cost or value, yielding knapsack-like, resource-constrained substring optimization problems.
- Relation to Sliding-Window and Packing Paradigms: MFSP demonstrates that frequency-based string matching admits precise resource-budget interpretations, connecting classic sliding-window substring search with packing-style optimization. This suggests a broader applicability in text algorithms and resource allocation frameworks (Shanto et al., 14 Jan 2026).
7. Summary
MFSP formalizes and solves, in optimal 00 time and 01 space, the problem of finding the longest substring under Parikh-component supply constraints. This sliding-window, two-pointer algorithm extends permutation matching, supports concise maximal-resource interpretations, and links string algorithms to combinatorial packing primitives (Shanto et al., 14 Jan 2026).