Added time and auxiliary space complexity