[IBM] OA 14 Dec 2024

1. Question 1

Given a set of distinct measurements taken at different times, find the minimum possible difference between any two measurements. Print all pairs of measurements that have this minimum difference in ascending order, with the pairs' elements ordered ascending, e.g., if a < b, the pair is a b. The values should have a single space between them.


Example
measurements = [-1, 3, 6, -5, 0]

The minimum absolute difference is 3, and the pairs with that difference are (3, 6) and (0, 3). When printing element pairs (i, j), they should be ordered ascending first by i and then by j.

0 3  
3 6  

Function Description
Complete the function minimumDifference in the editor.

minimumDifference has the following parameter:

  • int measurements[n]: an array of integers

Returns
NONE

Prints
Print the distinct pairs of measurements that have the minimum absolute difference, displayed in ascending order, with each pair separated by one space on a single line.


Constraints

  • 2 ≤ n ≤ 10^5
  • -10^9 ≤ measurements[i] ≤ 10^9

Input Format for Custom Testing

Input from stdin will be processed as follows and passed to the function.

  • The first line contains an integer n, the size of the array measurements.
  • Each of the next n lines contains an integer, measurements[i].

Sample Case 0

Sample Input 0

5  
6  
5  
4  
3  
7  

Sample Output 0

3 4  
4 5  
5 6  
6 7  

Explanation 0
The minimum absolute difference between any two elements in the array is 1, and there are four pairs with this difference: (3, 4), (4, 5), (5, 6), and (6, 7).


Sample Case 1

Sample Input 1

4  
1  
3  
5  
10  

Sample Output 1

1 3  
3 5  

Explanation 1
The minimum absolute difference between any two elements in the array is 2, and there are two such pairs: (1, 3) and (3, 5).


2. Question 2

In an edge computing environment, required hardware includes edge devices, input peripherals, and bundles that encompass both types. Each resource comes at a cost, with edge devices priced at edgeDeviceCost, peripherals at inputPeripheralCost, and bundles at bundleCost.

The challenge is to optimize the procurement of resources. The objective is to ensure the provision of the right quantities of edge devices and peripherals, allowing for a degree of flexibility, and accommodating extra equipment. This flexibility is provided to meet the requirements of the environment, which necessitates x edge devices and y peripherals. The primary goal is to minimize costs while simultaneously guaranteeing that the edge computing environment is equipped with all the essential resources. Compute and return the total expenditure.


Example
edgeDeviceCost = 1
inputPeripheralCost = 2
bundleCost = 2
x = 2
y = 1

The most cost-effective strategy is to purchase 1 edge device and 1 bundle pack with a total of 1 + 2 = 3 units. Any other approach results in a higher cost. The minimum total expenditure is 3 units.


Function Description
Complete the function getMinimumCost in the editor below.

getMinimumCost has the following parameter(s):

  • int edgeDeviceCost: the cost of an edge device
  • int inputPeripheralCost: the cost of an input peripheral
  • int bundleCost: the cost of a bundle containing both an edge device and an input peripheral
  • int x: the number of edge devices required
  • int y: the number of input peripherals required

Returns
long: the minimum expenditure necessary to ensure that the edge computing environment is fully equipped.


Constraints

  • 1 ≤ edgeDeviceCost, inputPeripheralCost, bundleCost, x, y ≤ 10^9

Input Format for Custom Testing
The first line contains an integer edgeDeviceCost.
The second line contains an integer inputPeripheralCost.
The third line contains an integer bundleCost.
The fourth line contains an integer x.
The fifth line contains an integer y.


Sample Case 0

Sample Input For Custom Testing

3  
2  
1  
4  
3  

Sample Output

4

Explanation
The optimal strategy is to buy 4 bundles for 4 units of money. This provides the environment with 4 edge devices (x ≤ 4) and 4 peripherals (y < 4).


Sample Case 1

Sample Input For Custom Testing

1  
20  
5  
9  
1  

Sample Output

13

Explanation
The optimal strategy is to get 8 edge devices and 1 bundle containing both, resulting in a total cost of 13 units. The environment will have 9 edge devices and 1 peripheral.


我们长期稳定承接各大科技公司如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 *