Uncategorized · 2 2 月, 2024 0

ByteDance 1/29-2/2 OA

Bytedance近期的几道OA真题,虽然难但是ac

Segment Queries

There are four arrays of data: cat and cnt, each consisting of n integers, where cat corresponds to cnt. These arrays represent categories and counts at each index. Additionally, there are two arrays of integers representing g queries: lq and rq, containing 1-based indices for the left and right ends of subarrays to consider in cat and cnt.

Process the queries in order and create an array of g values, where each answer corresponds to a query. For each query:

  1. Determine the maximum cnt within the subarrays in cat and cnt for each category.
  2. Store the sum of these maxima as the answer to the query.
  3. Clear the cnt values in the specified range.

After processing all queries, return the answer array.

Exmaple:

n=5
q=2
cat=[1,2,1,1,3]
cnt=[5,3,4,5,2]
l=[1,1]
r=[3,5]

Longest OR

There is an array of n integers, arr, and two integers mn and mX.
For each of arr‘s subarrays, find the binary value of the bitwise OR of all elements. If the number of 1 bits is between mn and mx, inciusive, it is a good subarray.
Determine the length of the longest goodsubarray.
Note: A subarray is any segment of adjacent elements in an array. For example, if arr = [1,2,3 [1,2]is a subarray but [1,3] is not.

Example:

mn = 1
mx = 2
n = 5
arr = [0,3,4,1,5]

Consider the subarray [3, 4, 1]. The bitwise OR of its elements is 7 (111), containing three 1 bits. As three 1 bits exceed mx = 2, this subarray is not considered good.

The following table illustrates various subarrays and the corresponding count of 1 bits in their bitwise OR:

| Subarray       | Bitwise OR | Count of 1 bits |
| -------------- | ----------- | --------------- |
| [0]            | 0           | 0               |
| [3]            | 3           | 2               |
| [4]            | 4           | 1               |
| [1]            | 1           | 1               |
| [5]            | 5           | 2               |
| [0, 3]         | 3           | 2               |
| [3, 4]         | 7           | 3               |
| [4, 1]         | 5           | 2               |
| [1, 5]         | 5           | 2               |
| [0, 3, 4]      | 7           | 3               |
| [3, 4, 1]      | 7           | 3               |
| [4, 1, 5]      | 7           | 3               |
| [0, 3, 4, 1]   | 7           | 3               |
| [3, 4, 1, 5]   | 7           | 3               |
| [0, 3, 4, 1, 5]| 7           | 3               |

The task is to determine the length of the longest subarray meeting the specified conditions.

Minimum Cycles

For a given array of n integers, arr, make the values equal usingthe minimum number of operations.

Either choose an element and apply the operation:

  • If the operation number is odd (e.g., first, third, fifth…), increase the element by 1.
  • If the operation number is even (e.g., second, fourth, sixth…), increase the element by 2.
  • or do nothing.

Only one element can change in an operation.
Calculate the minimum number of operations required tomake all elements equal.

我们还提供OA与VO的咨询与支持服务,如果有需要,请联系我们:

chen@csoahelp.com

We also provide consultation and support services for OA and VO. If needed, please feel free to contact us:

chen@csoahelp.com