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

Автор ashishranjan2828, история, 10 лет назад, По-английски

i hv tried this question with naive ....

but i think it can be done with the help of dp...

any help??

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

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Yes, it can be done in O(N) with prefix/suffix sums. Let gi be the amount of green squares in the prefix [1, i] and ri be the amount of red squares in the suffix [i, N]. Then the answer is the minimum gi + ri + 1.