fn prev(slice: &[i32], n: i32) -> i32
Calculate the change in distance moving left or up. The slice is sorted so we can use binary search instead of a linear scan.