Akpr's blog

By Akpr, history, 2 years ago, In English

Question

I did the above question in complexity of O(nlogn) and using vectors . I didn't knew why this happened as the with the given constraints my solution in nlogn should run!

But on changing vectors to array format ,it worked!!!

soln1

soln2

As you can see there is only one difference of conversion of vector maxel to an array

It would be kind if someone can tell how can this happen and where can i safely use a vector instead of an array.

thanks

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Akpr (previous revision, new revision, compare).

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Akpr (previous revision, new revision, compare).

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Akpr (previous revision, new revision, compare).

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Akpr (previous revision, new revision, compare).

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You are getting TLE because you are passing the vector by value, which adds one more 'N*' to your program's complexity.
Pass it by reference instead.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Cool it worked!! From now on will ensure to pass the vectors via reference

    Thanks