惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
MyScale Blog
MyScale Blog
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
T
Tenable Blog
S
Securelist
S
Schneier on Security
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
C
Cisco Blogs
The Hacker News
The Hacker News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
O
OpenAI News
V
Vulnerabilities – Threatpost
V
Visual Studio Blog
Security Latest
Security Latest
T
Threatpost
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Hacker News: Front Page
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
IT之家
IT之家
I
InfoQ
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
Know Your Adversary
Know Your Adversary
Martin Fowler
Martin Fowler
Forbes - Security
Forbes - Security
F
Full Disclosure
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
C
CERT Recently Published Vulnerability Notes
N
News and Events Feed by Topic
V
V2EX
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threat Research - Cisco Blogs
S
Secure Thoughts
量子位
博客园 - 【当耐特】

博客园 - 北叶青藤

2096. Step-By-Step Directions From a Binary Tree Node to Another Find path from root to a target node in Binary Tree When Dijkstra Algorithm Should be Use? 1188. Design Bounded Blocking Queue 1115. Print FooBar Alternately 1114. Print in Order 1242. Web Crawler Multithreaded Python Multi-threading bot ip Log Rate Limiter Same Word of HTML Labels Most Frequent Call Chain remove prefix in a words list Property Booking Optimizer minimum number 755. Pour Water Keyword Tagging in Reviews with Overlapping Matches Retryer Function Implementation 1125. Smallest Sufficient Team Print the terrain Split stay Task scheduling problem 滑雪问题 845. Longest Mountain in Array 723. Candy Crush 1539. Kth Missing Positive Number 1650. Lowest Common Ancestor of a Binary Tree III 424. Longest Repeating Character Replacement 843. Guess the Word 551. Student Attendance Record I
1102. Path With Maximum Minimum Value
北叶青藤 · 2026-03-20 · via 博客园 - 北叶青藤

Given an m x n integer matrix grid, return the maximum score of a path starting at (0, 0) and ending at (m - 1, n - 1) moving in the 4 cardinal directions.

The score of a path is the minimum value in that path.

  • For example, the score of the path 8 → 4 → 5 → 9 is 4.

Example 1:

Input: grid = [[5,4,5],[1,2,6],[7,4,6]]
Output: 4
Explanation: The path with the maximum score is highlighted in yellow. 

Example 2:

Input: grid = [[2,2,1,2,2,2],[1,2,2,2,1,2]]
Output: 2

Example 3:

Input: grid = [[3,4,6,3,4],[0,2,1,1,7],[8,8,3,2,7],[3,2,4,9,8],[4,1,2,0,0],[4,6,5,4,3]]
Output: 3

dfs approach

def maximumMinimumPath(grid):
    R, C = len(grid), len(grid[0])
    max_min_val = 0
    visited = [[False for _ in range(C)] for _ in range(R)]

    def dfs(r, c, current_min):
        nonlocal max_min_val
        
        # Update the minimum value seen on THIS specific path
        current_min = min(current_min, grid[r][c])
        
        # Pruning: If our current path is already worse than the best 
        # path we've found so far, stop exploring it.
        if current_min <= max_min_val:
            return

        # If we reached the goal, update our global best
        if r == R - 1 and c == C - 1:
            max_min_val = max(max_min_val, current_min)
            return

        visited[r][c] = True
        
        # Explore neighbors
        for dr, dc in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
            nr, nc = r + dr, c + dc
            
            if 0 <= nr < R and 0 <= nc < C and not visited[nr][nc]:
                dfs(nr, nc, current_min)
                
        # Backtrack: Unmark visited so other paths can use this cell
        visited[r][c] = False

    dfs(0, 0, grid[0][0])
    return max_min_val

better approach

To solve the Path With Maximum Minimum Value problem (LeetCode 1102), the goal is to find a path from $(0, 0)$ to $(R-1, C-1)$ such that the minimum value encountered along the path is as large as possible.

The Logic: "Greedy" Max-Priority Queue

This is a classic variation of a shortest path problem, but instead of minimizing the sum, we are maximizing the bottleneck.

We use a Max-Priority Queue (Max-Heap) to always explore the cell with the highest value currently available to us. By greedily picking the highest value neighbor, the first time we reach the destination, the "minimum value seen so far" is guaranteed to be the maximum possible minimum for any path.

 1 import heapq
 2 
 3 def maximumMinimumPath(grid):
 4     R, C = len(grid), len(grid[0])
 5     
 6     # Max-heap stores (-value, row, col)
 7     # We start at (0, 0)
 8     max_heap = [(-grid[0][0], 0, 0)]
 9     
10     # Keep track of the minimum value encountered on our current best path
11     res = grid[0][0]
12     
13     visited = [[False for _ in range(C)] for _ in range(R)]
14     visited[0][0] = True
15     
16     while max_heap:
17         val, r, c = heapq.heappop(max_heap)
18         val = -val # Convert back to positive
19         
20         # The bottleneck of the path is the minimum value we've seen
21         res = min(res, val)
22         
23         # If we reached the goal, this is the maximum possible bottleneck
24         if r == R - 1 and c == C - 1:
25             return res
26         
27         # Explore 4-directional neighbors
28         for dr, dc in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
29             nr, nc = r + dr, c + dc
30             
31             if 0 <= nr < R and 0 <= nc < C and not visited[nr][nc]:
32                 visited[nr][nc] = True
33                 heapq.heappush(max_heap, (-grid[nr][nc], nr, nc))
34                 
35     return res