best time to buy and search insert position and sort colors and spiral matrix