This is a verified interview question from Bny. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Memory MEX - BNY Online Assessment IGDTUW" covers key patterns like Arrays.
"There are `n` memory blocks, and the size of the `i`th block is given by the array `memoryBlocks[i]`, where `0 ≤ i < n`. The following operation can be performed on `memoryBlocks` one time: * Select an index `x`. * Increase `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. ### Note The MEX of an array is the smallest non-negative integer that does not appear in the array. ### Example ``` 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] ``` --- ### Function Description Complete the function ``` findValidSizes(memoryBlocks) ``` #### Parameters ``` int memoryBlocks[n] ``` #### Returns ``` int[]: all possible Valid Sizes that can be obtained using memoryBlocks, sorted in ascending order. ``` #### Constraints ``` 1 ≤ n ≤ 10^5 0 ≤ memoryBlocks[i] < n ``` --- ### Sample Input 0 ``` 3 0 2 2 ``` ``` memoryBlocks = [0,2,2] ``` ### Sample Output 0 ``` 0 1 ``` ### Explanation Without any operation, ``` MEX = 1 ``` Increase ``` memoryBlocks[0] ``` by `1`. Array becomes ``` [1,2,2] ``` Now ``` MEX = 0 ``` Hence the answer is ``` [0,1] ``` --- ### Sample Input 1 ``` 3 2 2 2 ``` ``` memoryBlocks = [2,2,2] ``` ### Sample Output 1 ``` 0 ``` ### Explanation Initially, ``` MEX = 0 ``` No sequence of operations can make MEX equal to `1` or higher. Hence the only possible Valid Size is ``` 0 ``` ---"
Join thousands of developers practicing for Bny.