Update gem_stones

better time and space comlexity