Can someone help me understand Self-Destructing Strings SDSTRING, was it asking to perform operations on the original string or that could be applied to a new string formed by the new operation?
Example:
AC code: 1000000001 ans —> 3
My code: 1000000001 —> -1 (because string could become 1010000101only if applied to original string)
if the string is of odd length or the string has only 1 unique character the print -1.
2)Else Make a queue, and append every element of a string in queue if the queue[0]==string[i], else if they are different then pop the leftist element from queue.
with this you can get a queue with only unique elements or no elements. Now again check if the queue has odd elements then print(-1) and if have even the print(len(queue))//2 because from queue we remove the elements that can be toggle hence string can be self-destructive if we toggle those elements.
This works for me and I got the correct answer but can someone helps me to understand the case when the given string is: 111110