Company: Tower research
Difficulty: medium
There are n memory blocks, and the size of the ith block is given by the array element memoryBlocks[i], where 0 <= i < n. The following operation can be performed on memoryBlocks one time: An index x can be selected. The size of memoryBlocks[x] can be increased by 1 unit, but only if memoryBlocks[x] is less than 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). The task is to return an array of all possible Valid Sizes that can be achieved using memoryBlocks, sorted in ascending order. Note: The MEX of memoryBlocks is the smallest non-negative integer not present in the array. Example: Given n = 3, memoryBlock = [0, 3, 4] If no operation on memoryBlocks is performed, then the Valid Size is 1. If x = 0, increase the size of memoryBlocks[0] by 1, then the Valid Size is 0. There are only two possible Valid Sizes. Hence, the answer is [0, 1], when sorted in ascending order. Function Descr