Editorial for DMOPC '19 Contest 4 P1 - Valid Strings
Submitting an official solution before solving the problem yourself is a bannable offence.
For this problem, note that the only relevant thing is whether the brackets are balanced. Since all characters are either digits or brackets, we don't care about invalid characters. Furthermore, the digits have no relevance to the solution since they can be placed anywhere without problem.
Therefore, we only have to determine if the brackets are balanced. A good way to do this is to keep track of bracket depth. Everytime you encounter an open bracket, increase this counter. Everytime you encounter a closed bracket, decrease this counter. If the counter is ever negative, the sequence is invalid. Also, if the counter is not ~0~ at the end of the operation, the sequence lacks closing brackets, and is also invalid.