[DRW] OA 2025 start – 2 Mar (generic)

Task 1

You are given N numbers on a circle, described by an array A. Find the maximum number of neighbouring pairs whose sums are even. One element can belong to only one pair.

Write a function:

def solution(A)

that, given an array A consisting of N integers, returns the maximum number of neighbouring pairs whose sums are even.

Examples

  1. Given A = [4, 2, 5, 8, 7, 3, 7], the function should return 2. We can create two pairs with even sums: (A[0], A[1]) and (A[4], A[5]). Another way to choose two pairs is: (A[0], A[1]) and (A[5], A[6]).
  2. Given A = [14, 21, 16, 35, 22], the function should return 1. There is only one qualifying pair: (A[0], A[4]).
  3. Given A = [5, 5, 5, 5, 5, 5], the function should return 3. We can create three pairs: (A[0], A[5]), (A[1], A[2]), and (A[3], A[4]).

Task 2

There is an array A consisting of N integers. Divide them into three non-empty groups. In each group, we calculate the difference between the largest and smallest integer. Our goal is to make the maximum of these differences as small as possible.

For example, given A = [11, 5, 3, 12, 6, 8, 1, 7, 4], we can divide the elements into three groups:

  • [3, 1, 4] – the difference between elements is 3
  • [5, 6, 8, 7] – the difference is also 3
  • [11, 12] – the difference is 1

The maximum difference equals 3, which is the minimum possible result.

Write a function:

def solution(A)

that, given an array A, returns the minimum possible result as explained above.

Examples

  1. For A = [11, 5, 3, 12, 6, 8, 1, 7, 4], the function should return 3, as explained above.
  2. For A = [10, 14, 12, 1000, 11, 15, 13, 1], the function should return 5. The elements of A should be divided into three groups as follows:
    • [1]
    • [10, 14, 12, 11, 15, 13]
    • [1000]
  3. For A = [4, 5, 7, 10, 10, 12, 12, 12], the function should return 2. The elements of A could be divided into these three groups:
    • [4, 5]
    • [7]
    • [10, 10, 12, 12]

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