LeetCopilot Logo
LeetCopilot
LeetCode Pattern/Binary Search/Minimize Maximum vs Maximize Minimum in Binary Search: Pattern Recognition Guide

Minimize Maximum vs Maximize Minimum in Binary Search: Pattern Recognition Guide

LeetCopilot Team
Dec 30, 2025
7 min read
Binary SearchMinimize MaximumMaximize MinimumPattern RecognitionOptimization
Learn to distinguish between minimize maximum and maximize minimum optimization patterns. Understand the feasibility direction, pointer updates, and how to recognize each pattern instantly.

"Minimize the maximum" and "maximize the minimum" sound similar, but they require opposite binary search logic. Confusing them leads to wrong answers.

This guide teaches you how to recognize each pattern, the exact template for each, and the key differences in feasibility and pointer updates.

TL;DR

Minimize Maximum:

  • Find smallest value that satisfies constraint
  • If x works, x+1 also works
  • Search for first True: right = mid

Maximize Minimum:

  • Find largest value that satisfies constraint
  • If x works, x-1 also works
  • Search for last True: left = mid + 1

The Two Patterns

Pattern 1: Minimize the Maximum

Problem structure: "What's the minimum [capacity/speed/load] such that [constraint] is satisfied?"

Examples:

  • Minimize eating speed to finish bananas
  • Minimize ship capacity to ship packages
  • Minimize maximum load among workers

Feasibility direction: If answer x works, larger values also work

code
Answer:     [1, 2, 3, 4, 5, 6, 7, 8]
Feasible:   [F, F, F, T, T, T, T, T]
                      ↑
            Find first T (minimum)

Template:

python
def minimize_maximum(min_val, max_val, is_feasible):
    left, right = min_val, max_val
    
    while left < right:
        mid = left + (right - left) // 2
        
        if is_feasible(mid):
            # mid works, try smaller
            right = mid
        else:
            # mid doesn't work, need larger
            left = mid + 1
    
    return left  # Minimum feasible value

Pattern 2: Maximize the Minimum

Problem structure: "What's the maximum [distance/force/gap] such that [constraint] is satisfied?"

Examples:

  • Maximize minimum distance between balls
  • Maximize minimum force between magnets
  • Maximize minimum gap in array

Feasibility direction: If answer x works, smaller values also work

code
Answer:     [1, 2, 3, 4, 5, 6, 7, 8]
Feasible:   [T, T, T, T, T, F, F, F]
                         ↑
            Find last T (maximum)

Template:

python
def maximize_minimum(min_val, max_val, is_feasible):
    left, right = min_val, max_val
    result = min_val
    
    while left <= right:
        mid = left + (right - left) // 2
        
        if is_feasible(mid):
            # mid works, try larger
            result = mid
            left = mid + 1
        else:
            # mid doesn't work, need smaller
            right = mid - 1
    
    return result  # Maximum feasible value

How to Recognize Each Pattern

Recognition Keywords

Minimize Maximum:

  • "Minimize the maximum..."
  • "Minimize the largest..."
  • "What's the minimum [X] to achieve [Y]?"
  • "Smallest [capacity/speed/load] such that..."

Maximize Minimum:

  • "Maximize the minimum..."
  • "Maximize the smallest..."
  • "What's the maximum [distance/gap] while maintaining [Y]?"
  • "Largest [distance/force] such that..."

Quick Test

Ask: "If answer x works, what about x+1?"

If x+1 also works: Minimize Maximum

  • Example: If speed 5 works, speed 6 also works
  • We want the minimum that works

If x+1 might not work: Maximize Minimum

  • Example: If distance 5 works, distance 6 might not work
  • We want the maximum that works

Side-by-Side Comparison

AspectMinimize MaximumMaximize Minimum
GoalFind smallest feasibleFind largest feasible
FeasibilityIf x works, x+1 worksIf x works, x-1 works
Search forFirst TrueLast True
Pointer update (feasible)right = midleft = mid + 1
Pointer update (infeasible)left = mid + 1right = mid - 1
Loop conditionleft < rightleft <= right
Returnleftresult

Example 1: Koko Eating Bananas (Minimize Maximum)

Problem: Find minimum eating speed to finish all bananas in h hours.

Pattern: Minimize Maximum (minimize speed)

Why: If speed k works, speed k+1 also works (faster is always ok)

Solution:

python
def minEatingSpeed(piles, h):
    def can_finish(speed):
        hours = sum((pile + speed - 1) // speed for pile in piles)
        return hours <= h
    
    left, right = 1, max(piles)
    
    while left < right:
        mid = left + (right - left) // 2
        
        if can_finish(mid):
            right = mid  # Try smaller speed
        else:
            left = mid + 1  # Need faster speed
    
    return left  # Minimum speed

Example 2: Magnetic Force (Maximize Minimum)

Problem: Place m balls to maximize minimum distance between any two balls.

Pattern: Maximize Minimum (maximize distance)

Why: If distance d works, distance d-1 also works (smaller is easier)

Solution:

python
def maxDistance(position, m):
    position.sort()
    
    def can_place(min_dist):
        count = 1
        last_pos = position[0]
        
        for pos in position[1:]:
            if pos - last_pos >= min_dist:
                count += 1
                last_pos = pos
                if count == m:
                    return True
        
        return count >= m
    
    left, right = 1, position[-1] - position[0]
    result = 1
    
    while left <= right:
        mid = left + (right - left) // 2
        
        if can_place(mid):
            result = mid  # Try larger distance
            left = mid + 1
        else:
            right = mid - 1  # Need smaller distance
    
    return result  # Maximum distance

Common Mistakes

Mistake 1: Wrong Pointer Update Direction

Wrong (Minimize Maximum):

python
if is_feasible(mid):
    left = mid + 1  # WRONG: should try smaller

Correct:

python
if is_feasible(mid):
    right = mid  # Try smaller for minimize

Mistake 2: Wrong Loop Condition

Wrong (Maximize Minimum):

python
while left < right:  # WRONG: should be <=

Correct:

python
while left <= right:  # Correct for maximize

Mistake 3: Confusing the Patterns

Wrong:

python
# Using minimize template for maximize problem

Correct:

python
# Identify pattern first, then use correct template

Practice Problems

Minimize Maximum:

  1. Koko Eating Bananas (#875)
  2. Capacity To Ship Packages (#1011)
  3. Split Array Largest Sum (#410)
  4. Minimize Max Distance to Gas Station (#774)

Maximize Minimum:
5. Magnetic Force Between Two Balls (#1552)
6. Aggressive Cows (classic problem)
7. Maximize Minimum Distance (variations)

Decision Framework

code
Step 1: Identify the optimization goal
├─ "Minimize the maximum" → Pattern 1
└─ "Maximize the minimum" → Pattern 2

Step 2: Verify feasibility direction
├─ If x works, does x+1 work? → Minimize Maximum
└─ If x works, does x-1 work? → Maximize Minimum

Step 3: Choose template
├─ Minimize Maximum: right = mid, left < right
└─ Maximize Minimum: left = mid + 1, left <= right

FAQ

Q: How do I remember which is which?

A: Minimize Maximum: Find first True (smallest that works)
Maximize Minimum: Find last True (largest that works)

Q: Can I use the same template for both?

A: No. The pointer updates and loop conditions are different.

Q: What if the problem doesn't say "minimize" or "maximize"?

A: Rephrase it. "What's the minimum X to achieve Y?" → Minimize Maximum

Q: Why different loop conditions?

A: Minimize uses left < right with right = mid (keeps mid as potential answer)
Maximize uses left <= right with result tracking (standard binary search)

Conclusion

Minimize Maximum and Maximize Minimum are opposite patterns that require different templates.

Key differences:

  • Feasibility direction: x+1 vs x-1
  • Search goal: First True vs Last True
  • Pointer updates: right = mid vs left = mid + 1
  • Loop condition: < vs <=

Recognition:

  • Keywords: "minimize maximum" vs "maximize minimum"
  • Feasibility test: If x works, does x+1 work?

Templates:

  • Minimize: Find first True with right = mid
  • Maximize: Find last True with left = mid + 1

Master both patterns and you'll solve optimization problems with confidence. For more details, see Binary Search on Answer and Why Binary Search on Answer Works.

Want to Practice LeetCode Smarter?

LeetCopilot is a free browser extension that enhances your LeetCode practice with AI-powered hints, personalized study notes, and realistic mock interviews — all designed to accelerate your coding interview preparation.

Also compatible with Edge, Brave, and Opera

Related Tutorials