FastPrepProfit Analysis
Problems/Profit Analysis

Profit Analysis

Virtu Financial logoVirtu Financial● MediumNEW GRADINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

The profit and loss for each month is represented by an integer array pnl. A positive value represents profit earned in that month, while a negative value represents a loss.

Return the maximum net profit obtainable from any non-empty contiguous segment of months whose length is at most k.

Function

getMaxProfit(pnl: int[], k: int) → long

Examples

Example 1

pnl = [-3,4,3,-2,2,5]k = 4return = 8

The segment [3,-2,2,5] has length 4 and total profit 3 + (-2) + 2 + 5 = 8. The segment [4,3,-2,2,5] has total profit 12, but its length is 5, which exceeds k = 4.

Constraints

  • 1 <= pnl.length <= 2 * 10^5
  • -10^9 <= pnl[i] <= 10^9
  • 1 <= k <= pnl.length

More Virtu Financial problems

  • Count Substrings With Identical CharactersOA · Seen Oct 2026
  • HexSpeakOA · Seen Oct 2026
  • Maximum Apples That Fit in a BoxOA · Seen Oct 2026
All Virtu Financial interview questionsSee Virtu Financial hiring insights
Saved
class Solution {
    public long getMaxProfit(int[] pnl, int k) {
        // write your code here
    }

}
Checking account…