LeetCode #3449 — HARD

Maximize the Minimum Game Score

Break down a hard problem into reliable checkpoints, edge-case handling, and complexity trade-offs.

Solve on LeetCode
The Problem

Problem Statement

You are given an array points of size n and an integer m. There is another array gameScore of size n, where gameScore[i] represents the score achieved at the ith game. Initially, gameScore[i] == 0 for all i.

You start at index -1, which is outside the array (before the first position at index 0). You can make at most m moves. In each move, you can either:

  • Increase the index by 1 and add points[i] to gameScore[i].
  • Decrease the index by 1 and add points[i] to gameScore[i].

Note that the index must always remain within the bounds of the array after the first move.

Return the maximum possible minimum value in gameScore after at most m moves.

Example 1:

Input: points = [2,4], m = 3

Output: 4

Explanation:

Initially, index i = -1 and gameScore = [0, 0].

Move Index gameScore
Increase i 0 [2, 0]
Increase i 1 [2, 4]
Decrease i 0 [4, 4]

The minimum value in gameScore is 4, and this is the maximum possible minimum among all configurations. Hence, 4 is the output.

Example 2:

Input: points = [1,2,3], m = 5

Output: 2

Explanation:

Initially, index i = -1 and gameScore = [0, 0, 0].

Move Index gameScore
Increase i 0 [1, 0, 0]
Increase i 1 [1, 2, 0]
Decrease i 0 [2, 2, 0]
Increase i 1 [2, 4, 0]
Increase i 2 [2, 4, 3]

The minimum value in gameScore is 2, and this is the maximum possible minimum among all configurations. Hence, 2 is the output.

Constraints:

  • 2 <= n == points.length <= 5 * 104
  • 1 <= points[i] <= 106
  • 1 <= m <= 109
Patterns Used

Roadmap

  1. Brute Force Baseline
  2. Core Insight
  3. Algorithm Walkthrough
  4. Edge Cases
  5. Full Annotated Code
  6. Interactive Study Demo
  7. Complexity Analysis
Step 01

Brute Force Baseline

Problem summary: You are given an array points of size n and an integer m. There is another array gameScore of size n, where gameScore[i] represents the score achieved at the ith game. Initially, gameScore[i] == 0 for all i. You start at index -1, which is outside the array (before the first position at index 0). You can make at most m moves. In each move, you can either: Increase the index by 1 and add points[i] to gameScore[i]. Decrease the index by 1 and add points[i] to gameScore[i]. Note that the index must always remain within the bounds of the array after the first move. Return the maximum possible minimum value in gameScore after at most m moves.

Baseline thinking

Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.

Pattern signal: Array · Binary Search · Greedy

Example 1

[2,4]
3

Example 2

[1,2,3]
5
Step 02

Core Insight

What unlocks the optimal approach

  • Can we use binary search?
  • What happens if you fix the game score as x?
  • We should go from i to (i + 1) back and forth, making the value for each index i (from left to right) no less than x.
Interview move: turn each hint into an invariant you can check after every iteration/recursion step.
Step 03

Algorithm Walkthrough

Iteration Checklist

  1. Define state (indices, window, stack, map, DP cell, or recursion frame).
  2. Apply one transition step and update the invariant.
  3. Record answer candidate when condition is met.
  4. Continue until all input is consumed.
Use the first example testcase as your mental trace to verify each transition.
Step 04

Edge Cases

Minimum Input
Single element / shortest valid input
Validate boundary behavior before entering the main loop or recursion.
Duplicates & Repeats
Repeated values / repeated states
Decide whether duplicates should be merged, skipped, or counted explicitly.
Extreme Constraints
Largest constraint values
Re-check complexity target against constraints to avoid time-limit issues.
Invalid / Corner Shape
Empty collections, zeros, or disconnected structures
Handle special-case structure before the core algorithm path.
Step 05

Full Annotated Code

Source-backed implementations are provided below for direct study and interview prep.

// Accepted solution for LeetCode #3449: Maximize the Minimum Game Score
class Solution {
  public long maxScore(int[] points, int m) {
    long l = 0;
    long r = ((long) m + 1) / 2 * points[0] + 1;

    while (l < r) {
      final long mid = (l + r + 1) / 2;
      if (isPossible(points, mid, m))
        l = mid;
      else
        r = mid - 1;
    }

    return l;
  }

  // Returns true if it is possible to achieve the maximum minimum value `x`
  // with `m` number of moves.
  private boolean isPossible(int[] points, long minVal, long m) {
    long moves = 0;
    long prevMoves = 0; // to track remaining moves from the previous point
    for (int i = 0; i < points.length; ++i) {
      // ceil(minVal / point)
      final long required = Math.max(0, (minVal + points[i] - 1) / points[i] - prevMoves);
      if (required > 0) {
        moves += 2L * required - 1;
        prevMoves = required - 1;
      } else if (i + 1 < points.length) {
        moves += 1;
        prevMoves = 0;
      }
      if (moves > m)
        return false;
    }
    return true;
  }
}
Step 06

Interactive Study Demo

Use this to step through a reusable interview workflow for this problem.

Press Step or Run All to begin.
Step 07

Complexity Analysis

Time
O(log n)
Space
O(1)

Approach Breakdown

LINEAR SCAN
O(n) time
O(1) space

Check every element from left to right until we find the target or exhaust the array. Each comparison is O(1), and we may visit all n elements, giving O(n). No extra space needed.

BINARY SEARCH
O(log n) time
O(1) space

Each comparison eliminates half the remaining search space. After k comparisons, the space is n/2ᵏ. We stop when the space is 1, so k = log₂ n. No extra memory needed — just two pointers (lo, hi).

Shortcut: Halving the input each step → O(log n). Works on any monotonic condition, not just sorted arrays.
Coach Notes

Common Mistakes

Review these before coding to avoid predictable interview regressions.

Off-by-one on range boundaries

Wrong move: Loop endpoints miss first/last candidate.

Usually fails on: Fails on minimal arrays and exact-boundary answers.

Fix: Re-derive loops from inclusive/exclusive ranges before coding.

Boundary update without `+1` / `-1`

Wrong move: Setting `lo = mid` or `hi = mid` can stall and create an infinite loop.

Usually fails on: Two-element ranges never converge.

Fix: Use `lo = mid + 1` or `hi = mid - 1` where appropriate.

Using greedy without proof

Wrong move: Locally optimal choices may fail globally.

Usually fails on: Counterexamples appear on crafted input orderings.

Fix: Verify with exchange argument or monotonic objective before committing.