Please read the new rule regarding the restriction on the use of AI tools. ×

Laiba07's blog

By Laiba07, history, 5 hours 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 - Make Equal Again

284045334

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

»
4 hours 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.