Create a NumberRegistry system that supports the following operations:
fetch: Retrieve the minimum unused number from the registry.isAvailable: Check if a specific number can be assigned.returnNumber: Make a previously assigned number available again.// Initialize a number registry with 4 numbers: 0, 1, 2, and 3. NumberRegistry registry = new NumberRegistry(4); // May return any unused number. Suppose it returns 1. registry.fetch(); // Suppose it returns 0. registry.fetch(); // Number 2 is still available, so this returns true. registry.isAvailable(2); // Only number 3 is left, so this call returns 3. registry.fetch(); // Number 2 is still available, so this returns true. registry.isAvailable(2); // Release the number 2 back to the registry. registry.returnNumber(2); // Now, number 2 is available again, so this returns true. registry.isAvailable(2);
0 to n - 1 where 1 ≤ n ≤ 9000.fetch, isAvailable, and returnNumber will be called at most 30,000 times in total.