Is the time comlexity of this code O(N^2)

Hello @shashankmaheshwari054 by using queue I think we have reduced it to O(N).

but we are also iterating in the queue using the for loop

@shashankmaheshwari054 yeah okay okay but then also it will not completely O(N^2) but in big o notation it will be O(N^2) only.

that means for writing in big O terms it will be O(n^2) otherwise it will take less time

@shashankmaheshwari054 yes exacly.
in big o notations we always write the smalles upper bound.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.