There are n memory blocks, and the size of the ith block is given by the array memoryBlocks[i], where 0 ≤ i < n.
The following operation can be performed on memoryBlocks one time:
x.memoryBlocks[x] by 1, but only if memoryBlocks[x] < n - 1.The smallest integer k not present in memoryBlocks after any number of operations is called a Valid Size, or the MEX (Minimum Excluded Value).
Your task is to return an array of all possible Valid Sizes that can be achieved using memoryBlocks, sorted in increasing order.
The MEX of an array is the smallest non-negative integer that does not appear in the array.
n = 3
memoryBlocks = [0, 3, 4]
If no operation is performed, the Valid Size is 1.
If x = 0, increase memoryBlocks[0] by 1, then the Valid Size is 0.
There are only two possible Valid Sizes.
Output:
[0, 1]
Complete the function
findValidSizes(memoryBlocks)
int memoryBlocks[n]
int[]:
all possible Valid Sizes that can be obtained using memoryBlocks,
sorted in ascending order.
1 ≤ n ≤ 10^5
0 ≤ memoryBlocks[i] < n
3
0
2
2
memoryBlocks = [0,2,2]
0
1
Without any operation,
MEX = 1
Increase
memoryBlocks[0]
by 1.
Array becomes
[1,2,2]
Now
MEX = 0
Hence the answer is
[0,1]
3
2
2
2
memoryBlocks = [2,2,2]
0
Initially,
MEX = 0
No sequence of operations can make MEX equal to 1 or higher.
Hence the only possible Valid Size is
0
Texas • Pending