Блог пользователя zhin

Автор zhin, история, 6 часов назад, По-английски

Question How to solve this ?

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

»
4 часа назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

I'm pretty sure coding a greedy is worth a shot. If $$$x = y$$$, the answer is just $$$\frac{nx}{2}$$$; if $$$x < y$$$, remove all identical characters you can, then you are left with at most $$$26$$$ different characters, and you just remove those using the $$$y$$$ operation; if $$$x > y$$$, store character counts in a heap or a SortedList and always use $$$y$$$ on the max and second max frequency characters. If there is only $$$1$$$ distinct character left, use $$$x$$$ on it.

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    For the $$$x>y$$$ condition, a better method would be to just check if character having the max frequency has the frequency greater than sum of frequency of all the other characters , then the answer would be $$$x*\frac{(2*(max freq) - length of string)}{2} + y*((length of string)-(max freq))$$$ and other wise, it would be possible to cancel out all of the characters with some other character and it would be end up being $$$ \frac{ny}{2} $$$.

    • »
      »
      »
      4 часа назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      That is a good point. It kind of reminds me of this problem.