xiaomi written test, snake array, space complexity with O(1)