Solve grid min path and sqrt by binary search | TikTok
|Home/Coding & Algorithms/TikTok
Solve grid min path and sqrt by binary search
TikTok
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
0
0
Given an m x n matrix of non-negative integers, find a path from the top-left to the bottom-right that minimizes the sum of cell values. You may only move right or down. Return both the minimum sum and one optimal path. Describe the algorithm, justify correctness, and analyze time/space complexity. Consider how to handle very large matrices that do not fit entirely in memory.
Implement sqrt(x) using binary search.
Version A: return floor(sqrt(x)) for a non-negative 32-bit or 64-bit integer x without using built-in square root functions; avoid overflow and analyze complexity.
Version B: return a double approximation within 1e-6 for a non-negative real x; discuss stopping conditions, numerical stability, and edge cases (x=0, 0<x<1, very large x).