FastPrepEarn the Most 🐝
Problems/Earn the Most 🐝

Earn the Most 🐝

Capital One logoCapital One● MediumFULLTIMENEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Our version is about 99% the same as the reported Capital One task.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz for sharing interview updates and helping keep this question up to date, including a report that it appeared again on November 20, 2026! Ω©(ΛŠα—œΛ‹*)و β™‘ πŸ’œ

You are given two equal-length arrays, prices and approach. For each day i, prices[i] is the currency price and approach[i] describes the trading action:

  • -1 means buy and contributes -prices[i] to profit.
  • 0 means hold and contributes 0.
  • 1 means sell and contributes prices[i].

You must choose exactly one contiguous window of length mrK. Rewrite the first half of that window to hold actions and the second half to sell actions. Actions outside the chosen window remain unchanged.

Return the maximum total profit obtainable after this rewrite, where total profit is the sum of every day's resulting contribution.

Function

earnTheMost(prices: int[], approach: int[], mrK: int) β†’ int

Examples

Example 1

prices = [2, 4, 1, 5, 10, 6]approach = [-1, 1, 0, 1, -1, 0]mrK = 4return = 18

The original strategy contributes -2 + 4 + 0 + 5 - 10 + 0 = -3.

Choose the window covering indices 2 through 5. Its rewritten actions are [0, 0, 1, 1], so the complete strategy becomes [-1, 1, 0, 0, 1, 1].

The resulting profit is -2 + 4 + 0 + 0 + 10 + 6 = 18, which is the maximum over all legal windows.

Constraints

  • prices.length = approach.length
  • 2 ≤ mrK ≤ prices.length
  • mrK is even.
  • Every prices[i] is a positive integer.
  • Every approach[i] is -1, 0, or 1.
  • The answer fits in a signed 32-bit integer.

More Capital One Online Assessment questions

  • Distinct Values on Maximum-Sum FramesOA Β· Seen Nov 2026
  • Lowest Number in an Open RangeOA Β· Seen Nov 2026
  • Branch with the Most FilesOA Β· Seen Nov 2026
  • Earliest Meeting Time for All EmployeesOA Β· Seen Nov 2026
  • Rank Football TeamsOA Β· Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA Β· Seen Oct 2026
  • Arithmetic Triplets After QueriesOA Β· Seen Oct 2026
  • Count One-Swap Number PairsOA Β· Seen Oct 2026
  • Sort Adjacent PairsOA Β· Seen Oct 2026
  • Bouncing Diagonal WeightsOA Β· Seen Oct 2026

Similar questions at other companies

  • Reschedule Meetings for Maximum Free TimeFivetran Β· OAFivetran interview questions
  • Minimum Cost to Convert Products to Variant AAmazon Β· OA
  • Minimum Swaps Required to Group All Red Balls TogetherMicrosoft Β· OAMicrosoft interview questions
  • Maximize Element FrequencyGoldman Sachs Β· ONSITE INTERVIEWGoldman Sachs interview questions
  • Minimum Cost to Merge Values into OnePayPal Β· OAPayPal interview questions
  • Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon Β· OA
  • Minimum Rounds to Complete All TasksInfosys Β· OAInfosys interview questions
  • Count Subarrays With Product Equal to KSalesforce Β· OASalesforce interview questions
  • Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group Β· OABoston Consulting Group interview questions
  • Count Servers With No Requests in a Time WindowIBM Β· OAIBM interview questions

Interview reports that mention this question

  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public int earnTheMost(int[] prices, int[] approach, int mrK) {
        // write your code here
    }

}
Checking account…