0

The task is similar to this one. Finding the largest balanced subarray (with equal number of each symbol). The difference is that the array consists of 4 different characters, not 0s and 1s. So the question would be how to change the approach with prefix sum in this case? Time complexity has to be no more than O(n^2), the string length is at most 10^5.

I was thinking about giving two characters values 1 and -1 and the other two 1000000 and -1000000, but it wouldn't work, simply because you can have a zero sum with half the symbols. Is there a simple way to do this?

Community
  • 1
  • 1
Simoroshka
  • 339
  • 1
  • 7
  • 18
  • I only see a quadratic solution, however, the constant factor is not going to be very high... so it might work for not so long strings... – heorhi Nov 03 '14 at 19:31
  • This one I can see too, but it is not the required solution... so there is a way. – Simoroshka Nov 03 '14 at 19:36

0 Answers0