Loading...
Loading...
You are given two integer arrays low and high of the same length n.
You want to select a group of indices. If the group has size k, then every selected index i must satisfy:
low[i] <= k - 1 <= high[i]
That is, each selected index tolerates between low[i] and high[i] other selected indices, inclusive.
Return the maximum possible group size k. If no non-empty group can be formed, return 0.
Input: low = [0, 1, 1, 2, 2], high = [1, 2, 2, 4, 4]
Output: 3
Explanation: Select indices 1, 2, and 3. The group size is k = 3, so each
selected index must allow 2 others: low[1] = 1 <= 2 <= 2 = high[1],
low[2] = 1 <= 2 <= 2 = high[2], and low[3] = 2 <= 2 <= 4 = high[3].
No group of size 4 or 5 is possible: only indices 3 and 4 allow 3 or more
others.
Input: low = [2, 2, 1], high = [2, 2, 1]
Output: 0
Explanation: A group of size 1 needs an index with low[i] = 0; none exists.
A group of size 2 needs two indices allowing exactly 1 other; only index 2
does. A group of size 3 needs all three indices to allow 2 others, but
index 2 allows at most 1. No valid group exists.
low.length = high.length ≤105low[i] ≤ high[i] ≤n−1