FastPrepMaximum Boat Distance with Resting Energy
Problems/Maximum Boat Distance with Resting Energy

Maximum Boat Distance with Resting Energy

Google logoGoogle● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The first Google report describes a boat. Each day it either moves forward by that day's wind value and spends one energy, or rests and gains one energy. The goal is the largest total distance. The report also says that resting at full energy leaves energy at k, that k is below 1000, and it adds a follow-up where wind values can be negative. In that case the answer is 0 if every day is negative. A second Google report gives the same rules for a person travelling over several days. It supplies the input used in Example 4, but no answer and no mention of the cap. Here, the 100,000-day limit and the 64-bit answer it needs are our choices. We worked out Example 4's answer using the first report's rules. Our version is about 90% the same as the reported questions.

A boat starts with energy k. On day i, it may move only with positive energy, gaining wind[i] distance and losing one energy, or rest, gaining one energy up to the cap k.

Wind may be negative. Return the maximum total distance after all days without allowing energy below zero. Resting is always allowed, so the answer is at least zero.

Function

maximumBoatDistance(k: int, wind: int[]) → long

Examples

Example 1

k = 2wind = [5,1,10]return = 15

Moving on days one and three after resting on day two yields fifteen.

Example 2

k = 1wind = [-5,-2]return = 0

Rest every day for zero distance.

Example 3

k = 0wind = [4,5]return = 0

With zero energy the boat cannot move.

Example 4

k = 3wind = [20,10,2,5,50,15,13]return = 108

Seven days with these values and 3 energy. Six moves are impossible: they need 6 energy, while the start gives 3 and the single rest day adds at most 1. Five moves are possible: move on days 1 and 2 (energy 3 to 1), rest on days 3 and 4 (back to 3), then move on days 5, 6 and 7. That uses the five largest values, 20 + 10 + 50 + 15 + 13 = 108.

Constraints

  • 0 <= k < 1000.
  • 0 <= wind.length <= 100000.
  • The answer fits in a signed 64-bit integer.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
  • Count Subsets With a Target SumSafe Security · ONSITE INTERVIEW
  • Maximum Subarray Sum with One DeletionOracle · ONSITE INTERVIEWOracle interview questions
  • Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Coin ChangeMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Maximum SubarrayUpstart · ONSITE INTERVIEWUpstart interview questions
  • Smallest Sufficient TeamExpedia · ONSITE INTERVIEWExpedia interview questions
  • Maximum Product SubarrayHartford Financial Services · ONSITE INTERVIEWHartford Financial Services interview questions
  • Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
  • Maximum Value from Circular HousesDigitalOcean · ONSITE INTERVIEWDigitalOcean interview questions

Interview reports that mention this question

  • Google SWE III ML Loops in India: 10 Experiences (Part 2 of 3)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long maximumBoatDistance(int k, int[] wind) {
        // write your code here
    }
}
Checking account…