Find All Minimal Framed Intervals
You are given an integer array biosequence of length M.
The array is guaranteed to be a permutation of all integers from 0 to M - 1, and it satisfies the following conditions:
- biosequence[0] = 0
- biosequence[M - 1] = M - 1
- There is no index i such that biosequence[i + 1] = biosequence[i] + 1
A segment is a contiguous subarray of biosequence.
A segment biosequence[L...R] is called a framed interval if all of the following are true:
- biosequence[L] is the smallest value in the segment
- biosequence[R] is the largest value in the segment
- biosequence[L] != biosequence[R]
- The segment contains every integer from biosequence[L] to biosequence[R] exactly once
In other words, if:
- minVal = biosequence[L]
- maxVal = biosequence[R]
then the segment must contain all integers in the range [minVal, maxVal], with no missing value and no extra value outside this range.
A framed interval is called an empodio if it does not contain any shorter framed interval completely inside it.
Return all empodia as 1-based index pairs [L, R], sorted in increasing order of starting index.
Example 1:
Input: biosequence = [0, 2, 1, 4, 3, 5]
Output: [[1, 6]]
Example 2:
Input: biosequence = [0, 4, 2, 1, 3, 6, 5, 7]
Output: [[1, 8]]
Now Your Turn!
Pick the correct output for the given inputInput: biosequence = [0, 3, 1, 2, 5, 4, 6]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- biosequence.length == M
- 4 ≤ M ≤ 100000
- biosequence is a permutation of integers from 0 to M - 1
- biosequence[0] = 0
- biosequence[M - 1] = M - 1
- There is no index i such that biosequence[i + 1] = biosequence[i] + 1