You are viewing a single comment's thread. Return to all comments →
I'm talking about space complexity. The space complexity is not O(1), and the space complexities in my 2 examples were different(one is O(n) as we are using a WHOLE n element array, while in the other we're using one variable).
You on the other hand, are talking about the time complexity. It is O(1) per query and that's correct. But how is space in any way O(1) ? There exists an n element array.
Seems like we missunderstood each other. I was talking about time complexity the whole time. As for the space complexity yes it is O(n), O(1) is not possible in this problem since we have to store the elements.
hi bro,i am a beginner.How to understand these concepts of time complexity and space complexity.
You should not worry about these things if you are a beginner,but since you have asked i have explained it here, take a look.
In the beginning your focus should be to complete the task without worrying about these time/space complexities.
My pleasure :)