Problem · Array

Maximum Decrypted Score

Learn this problem
MediumMicrosoft logoMicrosoftNEW GRADOA
See Microsoft hiring insights

Problem statement

You are given two arrays of equal length: scores and decryptionStatus. The value scores[i] is the sensitivity score of file i.

The value decryptionStatus[i] describes the current state of file i:

  • 1 means the file is already decrypted.
  • 0 means the file is still encrypted.

You may perform the following operation at most once: choose a contiguous subarray containing at most k files and decrypt every file in that subarray.

Return the maximum possible sum of the scores of all decrypted files after the optional operation.

Function

maximumDecryptedScore(scores: int[], decryptionStatus: int[], k: int) → long

Examples

Example 1

scores = [7,4,3,5]decryptionStatus = [1,0,0,0]k = 2return = 15

The already decrypted first file contributes 7. Choosing indices [2,3] decrypts files with scores 3 and 5, producing 7 + 3 + 5 = 15, which is greater than the totals from the other length-two segments.

Constraints

  • 1 <= scores.length <= 10^3
  • decryptionStatus.length == scores.length
  • 0 <= scores[i] <= 10^9
  • decryptionStatus[i] is either 0 or 1.
  • 1 <= k <= scores.length

More Microsoft problems

drafts saved locally
public long maximumDecryptedScore(int[] scores, int[] decryptionStatus, int k) {
  // Write your code here.
}
scores[7,4,3,5]
decryptionStatus[1,0,0,0]
k2
expected15
checking account