You are given a square grid of size dxd. It contains each of the numbers 1..n, where n = d^2. The numbers each occur once and only once, in arbitrary order, find the length of the longest sequence of adjacent consecutive numbers in the grid.
For example,
1 2 9 5 3 8 4 6 7
This contains three sequences of adjacent numbers [1, 2, 3] , [4, 5], and [6, 7, 8, 9]. The longest is [6, 7, 8, 9], which has length 4, and therefore the answer is 4.
No comments:
Post a Comment