sunny77's blog

By sunny77, history, 2 years ago, In English

I tried but I'm not understanding why.

Submission : 136141445

Problem : 1598C - Delete Two Elements

If there is a better solution, feel free to explain. :)

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

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

std::count's complexity is linear so your time complexity is $$$O(n^2)$$$. Use a map instead.

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

    Thank you for your reply. What will be the time complexity if I use a map? Will it be _O(NlogN)?

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

      Yes, it would be $$$O(n log n)$$$. You can use hashmap(unordered_map in C++), and your code run in $$$O(n)$$$ in average, but it is not guaranteed.