solution for the join-K rotate problem from the google code jam practice exercises