Click here to see the full article post
Can you explain why we only call possible function logN times? The distance between lo and hi is N^2, shouldn't it be logN^2?
@solidhouse4 Ah yes, thank you :)
Another way to solve this problem (more efficiently) is to use Disjoint Set data structure (like in Kruskal's algorithm for finding minimum spanning tree). This way you can reduce time complexity down to O(N^2). We go from 0 to N^2 and choose a Point on the grid with that value. Then we merge it with all its neighbours whose value is less than this Point's value.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.