Exact solution of a many body problem with nearest and next-nearest neighbour interactions