i cant understand the question can you explain it please
I cant uderstand the question
Refer this
they say solution is of order of n but
we are traversing whole array 3 times
1 making inc array
2 makind dec array
3 calculating ans
so how can it be O(n) not O(n^3)
can you answer it i closed doubt by mistake
@anubhavb11 All these 3 operations are O(n) operations.
So if your add them they become O(3n) which is equivalent to O(n).
Complexity will not be O(n^3)
There are no nested loops. If there had been a nested loop (3 branches) then complexity would be O(n^3)
1 Like