Worked on space complexity