Citadel OA | Disk Space Analysis | Citadel Online Assessment Question

A company is performing an analysis on the computers at its main office. The computers are spaced along a single row.

The analysis is performed in the following way:

  1. Choose a contiguous segment of a certain number of computers, starting from the beginning of the row.
  2. Analyze the available hard disk space on each of the computers.
  3. Determine the minimum available disk space within this segment.

After performing these steps for the first segment, it is then repeated for the next segment, continuing this procedure until the end of the row (for example, if the segment size is 4, computers 1 to 4 would be analyzed, then 2 to 5, etc.) Given this analysis procedure, find the maximum available disk space among all the minima that are found during the analysis.

Relevant Citadel OA Problems:

Input

  • space: the available hard disk space on each of the computers
  • x: the segment length to analyze

Output

the maximum of the minimum values available

Examples

Example 1:

Input:

1space = [8,2,4]
2x = 2

Output: 2

Explanation:

In this array of computers, the subarrays of size 2 are [8, 2] and [2, 4]. Thus, the initial analysis returns 2 and 2 because those are the minimal for the segments. Finally, the maximum of these values is 2. Therefore, the answer is 2.

Constraints

  • 1<=n<=10^6
  • 1<=x<=n
  • 1<=space[i]<=10^9

Try it yourself

Solution

โ†
โ†‘๐Ÿช„