Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

I tried to solve this question. But I got WA. I thought I chose a greedy approach but it seems like I have missed a counter case here. Can some please point that out. Thanks!!

1931C - Make Equal Again

284045334

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

»
3 часа назад, # |
Rev. 2   Проголосовать: нравится +2 Проголосовать: не нравится

You are solving the problem with the correct logic, but the implementation is incorrect. When converting the array to a string, removing occurrences of the first or last element in the original array works only if every number in the array consists of a single digit.

In cases like the example 22 2 2 2 2, when it is converted to the string 222222, your code will yield a result of zero because it incorrectly interprets the string as three instances of 22, which is wrong. The correct solution is to simulate the same logic, but using two pointers on the array.