[IBM SWE] OA 2025 start – 4 May (generic)

Question 1

The discovery of the structure of DNA in 1953 was made possible by Dr. Franklin's X-ray diffraction. Dr. Franklin's creation of the famous Photo 51 demonstrated the double-helix structure of deoxyribonucleic acid. Palindromic structures are widely studied in string processing and combinatorics and have applications in the analysis of DNA.

During her studies, Rosalind had come across a problem where she was given a string s consisting of lowercase English letters and the character '?'. She was required to develop an algorithm that would interpolate the string by replacing the question marks with lowercase English letters such that it can be rearranged to form a palindrome. If there were more than one palindrome possible, it had to be the alphabetically smallest one, and if there were none, the algorithm would return "-1" as the answer.

Note:

  • A string p is alphabetically smaller than string q, if p is a prefix of q and p is not equal to q or there exists j, such that p_j < q_j, and for all j < i, it is satisfied that p_j = q_j.
  • A palindrome is a string that reads the same backward as forward; for example, strings "z", "aaa", "aba", "abccba" are palindromes, but strings "hackerland", "reality", and "ab" are not.

Example

Given, s = "axxb??"

The two question marks can be replaced with the characters 'a' and 'b' respectively to form a string s = "axxabb". The string can be rearranged to "abxxba" which is the alphabetically smallest palindrome possible.

Function Description

Complete the function getSmallestPalindrome in the editor below.

getSmallestPalindrome(string s) → string
Returns
  • string: the alphabetically smallest palindrome possible or -1
Constraints
  • 1 ≤ |s| ≤ 10^5

Question 2

In a cloud infrastructure system, there are n servers, each with a performance score and activation status, represented by the arrays performanceScores and activationStatus. If the activation status is 1, the server is active, and 0 indicates an inactive server.

Implement a function that calculates the maximum possible total performance value of active servers by activating at most k consecutive servers.

Function Description

The function getMaxPerformanceSum takes the following inputs:

getMaxPerformanceSum(performanceScores: List[int], activationStatus: List[int], k: int) → int
Parameters
  • int performanceScores[n]: the performance scores of the servers
  • int activationStatus[n]: the activation status of the servers
  • int k: the maximum number of consecutive servers that can be activated

The function should return the maximum possible total performance score sum by activating the servers optimally.

Note:

A subarray is any contiguous segment of the array.

Example

Given n = 4, k = 2, performanceScores = [7, 4, 3, 5], and activationStatus = [1, 0, 0, 0]

Activate the last two consecutive servers
performanceScores   = [7, 4, 3, 5]
activationStatus    = [1, 0, 0, 0]
After activation    = [1, 0, 1, 1]

The answer is the sum of the activated servers after performing the activation optimally:
7 + 3 + 5 = 15

Constraints

  • 1 ≤ k ≤ n ≤ 10^5
  • 1 ≤ performanceScores[i] ≤ 10^4
  • 0 ≤ activationStatus[i] ≤ 1

Sample Case 0

Input
n = 6
performanceScores = [1, 3, 5, 2, 5, 4]
activationStatus = [1, 1, 0, 1, 0, 0]
k = 3

Output
16
Explanation

Activate the servers at indices 2 through 4, i.e., [1, 1, 0, 1, 0, 0][1, 1, 1, 1, 1, 0]

The performance score sum is 1 + 3 + 5 + 2 + 5 = 16

Sample Case 1

Input
n = 5
performanceScores = [1, 3, 2, 3, 6]
activationStatus = [0, 0, 0, 1, 0]
k = 2

Output
9
Explanation

Activate the servers at indices 1 through 2, i.e., [0, 0, 0, 1, 0][0, 1, 1, 1, 0]

The performance score sum is 3 + 6 = 9 (only considering active servers)

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