Welcome to IBM US-Standard General Software – IBM OA 真题

Question 1

Consider two arrays of integers, a[n] and b[n]. What is the maximum number of pairs that can be formed where a[i] > b[j]? Each element can be in no more than one pair.

Find the maximum number of such possible pairs.

Example
n = 3
a = [1, 2, 3]
b = [1, 2, 1]

Two ways the maximum number of pairs can be selected:

  • {a[1], b[0]} = {2, 1} and {a[2], b[2]} = {3, 1} are valid pairs.
  • {a[1], b[0]} = {2, 1} and {a[2], b[1]} = {3, 2} are valid pairs.

No more than 2 pairs can be formed, so return 2.

Function Description
Complete the function findNumOfPairs in the editor below.

findNumOfPairs has the following parameters:

  • int a[n]: an array of integers
  • int b[n]: an array of integers

Returns

  • int: the maximum number of pairs possible

Question 2

In a processor queue, there are n tasks. The priority levels of the tasks are represented by an array priority, in which each integer is a single digit. Tasks are classified as:

  • CPU-bound tasks are represented as odd integers in the array.
  • I/O-bound tasks are represented as even integers in the array.

To improve efficiency, the following operation can be performed:

  • Swap two adjacent tasks such that one is a CPU-bound task and the other is an I/O-bound task.

The goal is to reorder the tasks to achieve the lexicographically smallest possible priority sequence after making any number of valid operations (including zero). Return this lexicographically smallest sequence.

Note
A sequence is lexicographically smaller than another if it appears before it in dictionary order, comparing character by character from left to right.

Example
n = 6
priority = [2, 4, 6, 4, 3, 2]

The tasks in bold are selected for swapping.

An optimal sequence of swaps is as follows:

Before swappingAfter swapping
[2, 4, 6, 4, 3, 2][2, 4, 6, 3, 4, 2]
[2, 4, 6, 3, 4, 2][2, 4, 3, 6, 4, 2]
[2, 4, 3, 6, 4, 2][2, 3, 4, 6, 4, 2]

The lexicographically smallest possible priority sequence for the tasks is [2, 3, 4, 6, 4, 2].

Function Description
Complete the function getOptimalPriority in the editor with the following parameters:

  • int priority[n]: the priority sequence of the tasks

Returns

  • int[]: the lexicographically smallest possible priority sequence after making any number of valid operations (including zero)

Constraints

  • 1 ≤ n ≤ 2 × 10⁵
  • 0 ≤ priority[i] ≤ 9

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