Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Ring

Ring Distance

On a ring of length n where the ids are 0..n, what is the distance between two position u and v.

There are two 2 distances.

let (src, dst) = (u.min(v), u.max(v));
let d1 = dst - src;
let d2 = n - d1;

ABC376B