2023-11-08 08:09:02 +0000 UTC

Determine if a Cell Is Reachable at a Given Time

Code

func isReachableAtTime(sx int, sy int, fx int, fy int, t int) bool {
    vert := abs(sy, fy)
    dist := vert + max(0, abs(sx, fx) - vert)
    if dist == 0 && t == 1 {
        return false
    }
    return dist <= t
}

func abs(x, y int) int {
    if x > y {
        return x - y
    }
    return y - x
}