Laiba07's blog

By Laiba07, history, 3 months ago, In English

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 - Снова сделай равными

284045334

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 months ago, # |
Rev. 2   Vote: I like it +2 Vote: I do not like it

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.