- Define the priority key and whether the smallest or largest item should lead.
- Push each candidate when it becomes eligible.
- Discard stale entries when necessary and process the best live candidate.
Code notes
- 41 lines of C++ from the credited upstream file 1102.cpp.
- The implementation visibly relies on sequence storage, work queue.
- 2 loop blocks detected.
Complexity
Count heap pushes and pops; each normally contributes a logarithmic factor in the heap size.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1struct T {2 int i;3 int j;4 int val;5};6 7class Solution {8 public:9 int maximumMinimumPath(vector<vector<int>>& grid) {10 constexpr int kDirs[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};11 const int m = grid.size();12 const int n = grid[0].size();13 int ans = grid[0][0];14 vector<vector<bool>> seen(m, vector<bool>(n));15 auto compare = [](const T& a, const T& b) { return a.val < b.val; };16 priority_queue<T, vector<T>, decltype(compare)> maxHeap(compare);17 18 maxHeap.emplace(0, 0, grid[0][0]);19 20 while (!maxHeap.empty()) {21 const auto [i, j, val] = maxHeap.top();22 maxHeap.pop();23 ans = min(ans, val);24 if (i == m - 1 && j == n - 1)25 return ans;26 seen[i][j] = true;27 for (const auto& [dx, dy] : kDirs) {28 const int x = i + dx;29 const int y = j + dy;30 if (x < 0 || x == m || y < 0 || y == n)31 continue;32 if (seen[x][y])33 continue;34 maxHeap.emplace(x, y, grid[x][y]);35 }36 }37 38 throw;39 }40};41