Given two sorted lists of same length \$\{a_i\}\$ and \$\{b_i\}\$, find the smallest \$w\$ s.t. it's possible to connect each pair of points \$(0,a_i)\$ and \$(w,b_i)\$ with paths that
- x-coord always in open interval \$(0,w)\$, besides endpoints
- Every point on every path have at least one integer coord(=Path consists of horizonal and vertical segments, all of whose both end are integer point)
- No overlap
You can assume all inputs are positive. You can assume it possible(aka, no \$a_1=a_2\$ thing). You can decide increasing or decreasing input order. In case \$\{a_i\} = \{b_i\}\$, resulting 0 or 1 are both reasonable.
E.g. for a={1,3,5}, b={2,4,6}, smallest width is 2:
6 ┌─
5 ─┘
4 ┌─
3 ─┘
2 ┌─
1 ─┘
012
For a={1,2,5}, b={2,4,6} smallest width is 3:
6 ┌──
5 ─┘
4 ┌──
3 │
2 ─┘┌─
1 ──┘
0123
For a={1,2,5}, b={2,5,6} smallest width is also 3:
6 ┌──
5 ─┘┌─
4 ┌┘
3 │
2 ─┘┌─
1 ──┘
0123
Test cases
{1,3,5}, {2,4,6} => 2
{1,2,5}, {2,4,6} => 3
{1,2,5}, {2,5,6} => 3
{1,2,3}, {1,2,3} => 0 or 1
{1,2,3}, {4,5,6} => 4
{1,5,9}, {4,5,6} => 2
{3,5,7,9}, {1,3,5,7} => 3
{2,3,4,5}, {1,2,3,4} => 5
{1,2,3,4}, {2,5,7,9} => 5
{1,4,7}, {11,14,17} => 4
{1,4,7,13}, {11,14,17,18} => 5
{1,4,7,14}, {11,14,17,18} => 4
Shortest code wins
x-coord always in open interval (0,w), besides endpoints, vertical segments at end breaks it \$\endgroup\${1,2,3,4},{2,5,7,9}, which I think should give 5? Would be nice to have an example where that adjacency crowding thing is only on one side \$\endgroup\$[1,4,7,15], [11,14,17,18], not sure who is wrong \$\endgroup\$