rahul_1234's blog

By rahul_1234, history, 8 years ago, In English

Hi, I wanted to solve this question in O(N) but couldn't think of it. I did it in O(N logN ) using priority queue but can somebody provide me O(N) solution.

https://postimg.org/image/c31iexg13/

The link of question is not opening now, so I have shared the pic of question.

  • Vote: I like it
  • -15
  • Vote: I do not like it

»
8 years ago, # |
Rev. 2   Vote: I like it -18 Vote: I do not like it

no comments

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

    I guess it can be solved in O(N) as some of my friends did it in O(N).

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

      Not possible. Ur friends do not know how to estimate the TC. And I seriously doubt this can be solved using a PQ. Can u post a link to your solution?