[Citadel] OA 2025 start – 9 Jan (generic)

Problem Description

There are n jobs that can be executed in parallel on a processor, where the execution time of the i-th job is executionTime[i]. To speed up execution, the following strategy is used:

  • In one operation, a job is chosen as the major job, and it is executed for x seconds.
  • All other jobs are executed for y seconds, where y < x.

A job is complete when it has been executed for at least executionTime[i] seconds. Once a job is complete, it exits the pool.

Find the minimum number of operations required for the processor to completely execute all the jobs if run optimally.


Function Description

Complete the function citadelGetMinOperations in the editor.

int citadelGetMinOperations(int executionTime[n], int x, int y)

Parameters:

  • int executionTime[n]: An array representing the execution times of the jobs.
  • int x: The time for which the major job is executed in each operation.
  • int y: The time for which all other jobs are executed in each operation.

Returns:

  • int: The minimum number of operations required to complete all jobs.

Examples

Example 1:

Input:
executionTime = [3, 4, 1, 7, 6], x = 4, y = 2
Output:
3

Explanation:

  • Operation 1: Choose job 4 as the major job. Execution times:
    [1, 2, -1, 3, 4]. Job 3 is complete.
  • Operation 2: Choose job 4 again. Execution times:
    [-1, 0, -, -1, 2]. Jobs 1, 2, and 4 are complete.
  • Operation 3: Choose job 5. Execution times:
    [-, -, -, -, -2]. Job 5 is complete.

It takes 3 operations to execute all the jobs.


Example 2:

Input:
executionTime = [3, 3, 6, 3, 9], x = 3, y = 2
Output:
3

Explanation:

  • Operation 1: Choose job 5. Execution times:
    [1, 1, 4, 1, 6].
  • Operation 2: Choose job 5 again. Execution times:
    [-1, -1, 2, -1, 3]. Jobs 1, 2, and 4 are complete.
  • Operation 3: Choose job 5 again. Execution times:
    [-, -, 0, -, 0]. Jobs 3 and 5 are complete.

Example 3:

Input:
executionTime = [2, 3, 5], x = 3, y = 1
Output:
3

Explanation:

  • Operation 1: Choose job 3. Execution times:
    [1, 2, 2].
  • Operation 2: Choose job 3 again. Execution times:
    [0, 1, -1]. Jobs 1 and 3 are complete.
  • Operation 3: Choose job 2. Execution times:
    [-, -2, -]. Job 2 is complete.

Constraints:

  • 1 <= n <= 3 × 10^5
  • 1 <= executionTime[i] <= 10^9
  • 1 <= y < x <= 10^9

Key Insight:

  • The problem revolves around optimization: finding the best strategy to minimize the number of operations while ensuring that all jobs meet their required execution times.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *