Please explain how the complexity is O(1)

from my knowledge the complexity of told method is O(Nsquare). If not then please explain

Hi @mayankA47, the space complexity of this question is O(1) because we are taking extra space of just one bucket to calculate our answer. The rest of the values are updated inplace in the array given in the question. We will not consider the input array in space complexity because it was already given to us. We only consider the extra space that we use in our solution.

Hope this resolved your query. If you still have a doubt, you can reply to this thread, otherwise mark it as resolved.