How would you calculate time and space complexity for an initial solution, and identify the bottlenecks to optimize it?