Find the Safest Path in a Grid - BFS & Binary Search, BFS & Dijkstra's [JS]
Description Solution 1: BFS & Binary Search Use multi-source BFS to find each cell's minimum distance to a thief. We start the BFS at the thief cells and expand outwards. Binary search for the maximum possible minSafeness factor. To check whether a minSafeness is possible, use BFS to check whether there exists a valid path from (0, 0) to (n-1, n-1) using only cells with safeness >= minSafeness . Time Complexity: O(n^2 log(n^2)) 512ms Space Complexity: O(n^2) 91.4MB var maximumSafenessFactor = function ( grid ) { let safeness = getSafeness(grid), n = grid.length; let low = 0 , high = n * n; while (low < high) { let mid = Math .ceil((low + high) / 2 ); if (isEnough(safeness, mid)) low = mid; else high = mid - 1 ; } return low; }; function isEnough ( safeness, minSafeness ) { // use bfs to check whether a valid path exists using only cells with safeness >= minSafeness let n = safen...