[Goldman Sachs] OA 2025 start – 12 Mar (generic)

1. Effective Manager

A product manager has to organize n meetings with different people. Meeting with each person results in an increase or decrease in the effectiveness index of the manager. The manager wants to organize the meetings such that the index remains positive for as many meetings as possible. Find the maximum number of meetings for which the effectiveness index is positive. The index at the beginning is 0.

Note: After the meetings begin, the index must remain above 0 to be positive.

Example

n = 4 effectiveness = [1, -20, 3, -2]





One optimal meeting order is [3, -2, 1, -20]. The index is positive for the first three meetings, after which it is 3 - 2 + 1 = 1. So, the answer is 3. There is no way to have 4 meetings with a positive index.

Function Description

Complete the function maxMeetings in the editor.

maxMeetings has the following parameter:

  • int effectiveness[n]: the increase or decrease effectiveness for each meeting.

Returns

  • int: the maximum possible number of meetings while maintaining a positive index.

Constraints

  • 1 ≤ n ≤ 10^5
  • -10^9 ≤ effectiveness[i] ≤ 10^9

2. Bitwise XOR Subsequences

A subsequence of an array is formed by removing zero or more elements from an array without changing the order of the remaining elements. In a valid subsequence, each pair of adjacent elements has bitwise XOR equal to k. Note that any subsequence of length 1 is valid regardless of the value of k because there is no pair of adjacent elements in such a subsequence.

Given an array of integers and integer k, determine the length of the longest valid subsequence in the array.

Example

n = 5 arr = [2, 1, 3, 5, 2] k = 2





The subsequence [1,3] is valid because for all pairs of adjacent elements it has (1 and 3), the bitwise XOR of such elements is equal to k (1 XOR 3 = 2). There are no other valid subsequences that are longer than 2. For example, subsequence [2,1,3] is not valid because 2 XOR 1 does not equal 2.

Function Description

Complete the function maxSubsequenceLength in the editor below. The function must return the length of the longest valid subsequence of the array, given parameter k.

maxSubsequenceLength has the following parameter(s):

  • int n: the size of arr
  • int arr[n]: an array of integers
  • int k: an integer

Constraints

  • 1 ≤ n ≤ 10^5
  • 0 ≤ arr[i] ≤ 10^6
  • 0 ≤ k ≤ 10^6

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